MemoryCache.AddOrGetExisting Método

Definição

Insere uma entrada de cache no cache.Inserts a cache entry into the cache.

Sobrecargas

AddOrGetExisting(CacheItem, CacheItemPolicy)

Adiciona uma entrada de cache no cache usando a instância CacheItem especificada e os detalhes sobre como remover a entrada.Adds a cache entry into the cache using the specified CacheItem instance and details about how to evict the entry.

AddOrGetExisting(String, Object, DateTimeOffset, String)

Adiciona uma entrada de cache ao cache usando a chave especificada e um valor de expiração absoluta.Adds a cache entry into the cache using the specified key and a value and an absolute expiration value.

AddOrGetExisting(String, Object, CacheItemPolicy, String)

Insere uma entrada de cache no cache usando a chave e o valor especificados, bem como os detalhes especificados para sua remoção.Inserts a cache entry into the cache using the specified key and value and the specified details for how it is to be evicted.

Comentários

As AddOrGetExisting sobrecargas de método são usadas para inserir uma entrada de cache no cache.The AddOrGetExisting method overloads are used to insert a cache entry into the cache. Se uma entrada de cache com uma chave correspondente não existir, esses métodos inserirão uma nova entrada.If a cache entry with a matching key does not exist, these methods insert a new entry. Se uma entrada de cache com uma chave correspondente já existir, ela retornará a entrada existente.If a cache entry with a matching key already exists, they return the existing entry.

AddOrGetExisting(CacheItem, CacheItemPolicy)

Adiciona uma entrada de cache no cache usando a instância CacheItem especificada e os detalhes sobre como remover a entrada.Adds a cache entry into the cache using the specified CacheItem instance and details about how to evict the entry.

public:
 override System::Runtime::Caching::CacheItem ^ AddOrGetExisting(System::Runtime::Caching::CacheItem ^ item, System::Runtime::Caching::CacheItemPolicy ^ policy);
public override System.Runtime.Caching.CacheItem AddOrGetExisting (System.Runtime.Caching.CacheItem item, System.Runtime.Caching.CacheItemPolicy policy);
override this.AddOrGetExisting : System.Runtime.Caching.CacheItem * System.Runtime.Caching.CacheItemPolicy -> System.Runtime.Caching.CacheItem
Public Overrides Function AddOrGetExisting (item As CacheItem, policy As CacheItemPolicy) As CacheItem

Parâmetros

item
CacheItem

O objeto a adicionar.The object to add.

policy
CacheItemPolicy

Um objeto que contém os detalhes da remoção da entrada de cache.An object that contains eviction details for the cache entry. Esse objeto fornece mais opções de remoção do que uma expiração absoluta simples.This object provides more options for eviction than a simple absolute expiration.

Retornos

CacheItem

Se houver uma entrada de cache com a mesma chave, a entrada de cache existente; caso contrário, null.If a cache entry with the same key exists, the existing cache entry; otherwise, null.

Exceções

A propriedade Value é null.The Value property is null.

Os valores de expiração absoluta e deslizante para o objeto CacheItemPolicy são definidos como valores diferentes dos padrões dos campos InfiniteAbsoluteExpiration e NoSlidingExpiration.Both the absolute and sliding expiration values for the CacheItemPolicy object are set to values other than the defaults of InfiniteAbsoluteExpiration and NoSlidingExpiration fields. A classe MemoryCache não pode definir a política de expiração com base em uma combinação de uma expiração absoluta e uma expiração deslizante.The MemoryCache class cannot set expiration policy based on a combination of an absolute expiration and a sliding expiration. Somente uma configuração de expiração pode ser definida explicitamente quando você usa a instância MemoryCache.Only one expiration setting can be explicitly set when you use the MemoryCache instance. A outra configuração de expiração deve ser definida como o campo InfiniteAbsoluteExpiration ou o NoSlidingExpiration.The other expiration setting must be set to InfiniteAbsoluteExpiration field or NoSlidingExpiration field.

A propriedade SlidingExpiration é definida com um valor menor que Zero.The SlidingExpiration property is set to a value less than Zero.

- ou --or- A propriedade SlidingExpiration é definida com um valor maior que um ano.The SlidingExpiration property is set to a value greater than one year.

- ou --or- A propriedade Priority não é um valor da enumeração CacheItemPriority.The Priority property is not a value of the CacheItemPriority enumeration.

Comentários

O item parâmetro fornece a chave e o valor que é usado pelo método.The item parameter supplies the key and the value that is used by the method. Se o cache tiver uma entrada de cache com a mesma chave que a chave do item parâmetro, o método retornará a entrada existente como uma CacheItem instância.If the cache has a cache entry with the same key as the key of the item parameter, the method returns the existing entry as a CacheItem instance. Se não houver nenhuma entrada de cache existente, o método criará uma nova usando a chave e o valor fornecidos pelo item parâmetro e com os detalhes de remoção especificados por policy .If there is no existing cache entry, the method creates a new one by using the key and value supplied by the item parameter, and with the eviction details specified by policy.

Aviso

As sobrecargas do método Add e AddOrGetExisting não dão suporte à propriedade UpdateCallback.The Add and AddOrGetExisting method overloads do not support the UpdateCallback property. Portanto, para definir a propriedade UpdateCallback para uma entrada de cache, use as sobrecargas do método Set.Therefore, to set the UpdateCallback property for a cache entry, use the Set method overloads instead.

Aplica-se a

AddOrGetExisting(String, Object, DateTimeOffset, String)

Adiciona uma entrada de cache ao cache usando a chave especificada e um valor de expiração absoluta.Adds a cache entry into the cache using the specified key and a value and an absolute expiration value.

public override object AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = default);
override this.AddOrGetExisting : string * obj * DateTimeOffset * string -> obj
Public Overrides Function AddOrGetExisting (key As String, value As Object, absoluteExpiration As DateTimeOffset, Optional regionName As String = Nothing) As Object

Parâmetros

key
String

Um identificador exclusivo para a entrada de cache a ser adicionada.A unique identifier for the cache entry to add.

value
Object

Os dados de entrada de cache.The data for the cache entry.

absoluteExpiration
DateTimeOffset

A data e a hora fixas em que a entrada de cache vai expirar.The fixed date and time at which the cache entry will expire.

regionName
String

Uma região nomeada no cache à qual uma entrada de cache pode ser adicionada.A named region in the cache to which a cache entry can be added. Não passe um valor para esse parâmetro.Do not pass a value for this parameter. Esse parâmetro é null por padrão, pois a classe MemoryCache não implementa regiões.This parameter is null by default, because the MemoryCache class does not implement regions.

Retornos

Object

Se houver uma entrada de cache com a mesma chave, a entrada de cache existente; caso contrário, null.If a cache entry with the same key exists, the existing cache entry; otherwise, null.

Exceções

value não é null.value is not null.

regionName não é null.regionName is not null.

Os valores de expiração absoluta e deslizante para o objeto CacheItemPolicy são definidos como valores diferentes dos padrões dos campos InfiniteAbsoluteExpiration e NoSlidingExpiration.Both the absolute and sliding expiration values for the CacheItemPolicy object are set to values other than the defaults of InfiniteAbsoluteExpiration and NoSlidingExpiration fields. A classe MemoryCache não pode definir a política de expiração com base em uma combinação de uma expiração absoluta e uma expiração deslizante.The MemoryCache class cannot set expiration policy based on a combination of an absolute expiration and a sliding expiration. Somente uma configuração de expiração pode ser definida explicitamente quando você usa a instância MemoryCache.Only one expiration setting can be explicitly set when you use the MemoryCache instance. A outra configuração de expiração deve ser definida como InfiniteAbsoluteExpiration ou NoSlidingExpirationThe other expiration setting must be set to InfiniteAbsoluteExpiration or NoSlidingExpiration

A propriedade SlidingExpiration é definida com um valor menor que Zero.The SlidingExpiration property is set to a value less than Zero.

- ou --or- A propriedade SlidingExpiration é definida com um valor maior que um ano.The SlidingExpiration property is set to a value greater than one year.

- ou --or- A propriedade Priority não é um valor da enumeração CacheItemPriority.The Priority property is not a value of the CacheItemPriority enumeration.

Comentários

Se o cache não tiver uma entrada de cache cuja chave corresponda ao key parâmetro, uma nova entrada de cache será criada e a MemoryCache.AddOrGetExisting sobrecarga do método retornará null .If the cache does not have a cache entry whose key matches the key parameter, a new cache entry is created, and the MemoryCache.AddOrGetExisting method overload returns null. Se existir uma entrada de cache correspondente, a entrada existente será retornada.If a matching cache entry exists, the existing entry is returned.

Aviso

As sobrecargas do método Add e AddOrGetExisting não dão suporte à propriedade UpdateCallback.The Add and AddOrGetExisting method overloads do not support the UpdateCallback property. Portanto, para definir a propriedade UpdateCallback para uma entrada de cache, use as sobrecargas do método Set.Therefore, to set the UpdateCallback property for a cache entry, use the Set method overloads instead.

Aplica-se a

AddOrGetExisting(String, Object, CacheItemPolicy, String)

Insere uma entrada de cache no cache usando a chave e o valor especificados, bem como os detalhes especificados para sua remoção.Inserts a cache entry into the cache using the specified key and value and the specified details for how it is to be evicted.

public override object AddOrGetExisting (string key, object value, System.Runtime.Caching.CacheItemPolicy policy, string regionName = default);
override this.AddOrGetExisting : string * obj * System.Runtime.Caching.CacheItemPolicy * string -> obj
Public Overrides Function AddOrGetExisting (key As String, value As Object, policy As CacheItemPolicy, Optional regionName As String = Nothing) As Object

Parâmetros

key
String

Um identificador exclusivo da entrada de cache a ser adicionada ou obtida.A unique identifier for the cache entry to add or get.

value
Object

Os dados de entrada de cache.The data for the cache entry.

policy
CacheItemPolicy

Um objeto que contém os detalhes da remoção da entrada de cache.An object that contains eviction details for the cache entry. Esse objeto fornece mais opções de remoção do que uma expiração absoluta simples.This object provides more options for eviction than a simple absolute expiration.

regionName
String

Uma região nomeada no cache à qual uma entrada de cache pode ser adicionada.A named region in the cache to which a cache entry can be added. Não passe um valor para esse parâmetro.Do not pass a value for this parameter. Por padrão, esse parâmetro é null, pois a classe MemoryCache não implementa regiões.By default, this parameter is null, because the MemoryCache class does not implement regions.

Retornos

Object

Se uma entrada de cache correspondente já existir, uma entrada de cache; caso contrário, null.If a matching cache entry already exists, a cache entry; otherwise, null.

Exceções

value é null.value is null.

Os valores de expiração absoluta e deslizante para o objeto CacheItemPolicy são definidos como valores diferentes dos padrões de InfiniteAbsoluteExpiration e NoSlidingExpiration.Both the absolute and sliding expiration values of CacheItemPolicy object are set to values other than the defaults of InfiniteAbsoluteExpiration and NoSlidingExpiration. A classe MemoryCache não pode definir a política de expiração com base em uma combinação de uma expiração absoluta e uma expiração deslizante.The MemoryCache class cannot set expiration policy based on a combination of both an absolute and a sliding expiration. Somente uma configuração de expiração pode ser definida explicitamente quando você usa a classe MemoryCache.Only one expiration setting can be explicitly set when you use the MemoryCache class. A outra configuração deve ser definida como InfiniteAbsoluteExpiration ou NoSlidingExpiration.The other setting must be set to InfiniteAbsoluteExpiration or NoSlidingExpiration.

- ou --or- O retorno de chamada de remoção e o retorno de chamada de atualização foram especificados para CacheItemPolicy.Both the removal callback and the update callback have been specified for CacheItemPolicy. O MemoryCache dá suporte apenas ao uso de um tipo de retorno de chamada por entrada de cache.The MemoryCache only supports using one type of callback per cache entry.

A propriedade SlidingExpiration é definida com um valor menor que Zero.The SlidingExpiration property is set to a value less than Zero.

- ou --or- O SlidingExpiration foi definido como um valor maior que um ano.The SlidingExpiration has been set to a value greater than one year.

- ou --or- A propriedade Priority não é um valor da enumeração CacheItemPriority.The Priority property is not a value of the CacheItemPriority enumeration.

Comentários

Aviso

As sobrecargas do método Add e AddOrGetExisting não dão suporte à propriedade UpdateCallback.The Add and AddOrGetExisting method overloads do not support the UpdateCallback property. Portanto, para definir a propriedade UpdateCallback para uma entrada de cache, use as sobrecargas do método Set.Therefore, to set the UpdateCallback property for a cache entry, use the Set method overloads instead.

Aplica-se a