ObjectCache.AddOrGetExisting ObjectCache.AddOrGetExisting ObjectCache.AddOrGetExisting ObjectCache.AddOrGetExisting Method

定义

在派生类中重写时,尝试向缓存中插入缓存项,并返回具有匹配键的现有缓存项。When overridden in a derived class, tries to insert a cache entry into the cache, and returns an existing cache entry with a matching key.

重载

AddOrGetExisting(CacheItem, CacheItemPolicy) AddOrGetExisting(CacheItem, CacheItemPolicy) AddOrGetExisting(CacheItem, CacheItemPolicy) AddOrGetExisting(CacheItem, CacheItemPolicy)

在派生类中重写时,向缓存中插入指定的 CacheItem 对象,同时指定有关如何逐出该项的信息。When overridden in a derived class, inserts the specified CacheItem object into the cache, specifying information about how the entry will be evicted.

AddOrGetExisting(String, Object, DateTimeOffset, String) AddOrGetExisting(String, Object, DateTimeOffset, String) AddOrGetExisting(String, Object, DateTimeOffset, String)

在派生类中重写时,通过使用键、表示缓存项的对象、绝对过期值和要添加缓存的可选区域,向缓存中插入缓存项。When overridden in a derived class, inserts a cache entry into the cache, by using a key, an object for the cache entry, an absolute expiration value, and an optional region to add the cache into.

AddOrGetExisting(String, Object, CacheItemPolicy, String) AddOrGetExisting(String, Object, CacheItemPolicy, String) AddOrGetExisting(String, Object, CacheItemPolicy, String)

在派生类中重写时,向缓存中插入缓存项,并指定该缓存项的键和值以及有关如何逐出该项的信息。When overridden in a derived class, inserts a cache entry into the cache, specifying a key and a value for the cache entry, and information about how the entry will be evicted.

注解

AddOrGetExisting方法重载将项插入到缓存。The AddOrGetExisting method overloads insert an entry into the cache. 如果已存在具有匹配键的缓存项,它们将返回现有条目。If a cache entry with a matching key already exists, they return the existing entry. 缓存项可以是CacheItem对象或泛型对象。The cache entry can be a CacheItem object or a generic object.

之间的一个区别AddOrGetExisting重载和Add重载。There is one difference between the AddOrGetExisting overloads and the Add overloads. 这些重载的方法尝试插入缓存项时,如果找到一个现有项,具有匹配的现有密钥插入缓存项时AddOrGetExisting重载将返回现有的缓存项。When these overloaded methods try to insert a cache entry, if an existing entry is found that has a key that matches an existing inserted cache entry, the AddOrGetExisting overloads return the existing cache entry. Add重载不这样做。The Add overloads do not.

AddOrGetExisting(CacheItem, CacheItemPolicy) AddOrGetExisting(CacheItem, CacheItemPolicy) AddOrGetExisting(CacheItem, CacheItemPolicy) AddOrGetExisting(CacheItem, CacheItemPolicy)

在派生类中重写时,向缓存中插入指定的 CacheItem 对象,同时指定有关如何逐出该项的信息。When overridden in a derived class, inserts the specified CacheItem object into the cache, specifying information about how the entry will be evicted.

public:
 abstract System::Runtime::Caching::CacheItem ^ AddOrGetExisting(System::Runtime::Caching::CacheItem ^ value, System::Runtime::Caching::CacheItemPolicy ^ policy);
public abstract System.Runtime.Caching.CacheItem AddOrGetExisting (System.Runtime.Caching.CacheItem value, System.Runtime.Caching.CacheItemPolicy policy);
abstract member AddOrGetExisting : System.Runtime.Caching.CacheItem * System.Runtime.Caching.CacheItemPolicy -> System.Runtime.Caching.CacheItem
Public MustOverride Function AddOrGetExisting (value As CacheItem, policy As CacheItemPolicy) As CacheItem

参数

value
CacheItem CacheItem CacheItem CacheItem

要插入的对象。The object to insert.

policy
CacheItemPolicy CacheItemPolicy CacheItemPolicy CacheItemPolicy

一个包含该缓存项的逐出详细信息的对象。An object that contains eviction details for the cache entry. 此对象提供比简单绝对过期更多的逐出选项。This object provides more options for eviction than a simple absolute expiration.

返回

如果存在具有相同键的缓存项,则为指定的缓存项;否则为 nullIf a cache entry with the same key exists, the specified cache entry; otherwise, null.

AddOrGetExisting(String, Object, DateTimeOffset, String) AddOrGetExisting(String, Object, DateTimeOffset, String) AddOrGetExisting(String, Object, DateTimeOffset, String)

在派生类中重写时,通过使用键、表示缓存项的对象、绝对过期值和要添加缓存的可选区域,向缓存中插入缓存项。When overridden in a derived class, inserts a cache entry into the cache, by using a key, an object for the cache entry, an absolute expiration value, and an optional region to add the cache into.

public abstract object AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null);
abstract member AddOrGetExisting : string * obj * DateTimeOffset * string -> obj
Public MustOverride Function AddOrGetExisting (key As String, value As Object, absoluteExpiration As DateTimeOffset, Optional regionName As String = null) As Object

参数

key
String String String String

该缓存项的唯一标识符。A unique identifier for the cache entry.

value
Object Object Object Object

要插入的对象。The object to insert.

absoluteExpiration
DateTimeOffset DateTimeOffset DateTimeOffset DateTimeOffset

缓存项的固定的过期日期和时间。The fixed date and time at which the cache entry will expire.

regionName
String String String String

可选。Optional. 缓存中的一个可用来添加缓存项的命名区域(如果实现了区域)。A named region in the cache to which the cache entry can be added, if regions are implemented. 可选参数的默认值为 nullThe default value for the optional parameter is null.

返回

如果存在具有相同键的缓存项,则为指定缓存项的值;否则为 nullIf a cache entry with the same key exists, the specified cache entry's value; otherwise, null.

注解

AddOrGetExisting(String, Object, DateTimeOffset, String)方法重载方法返回一个对象值,不CacheItem对象。This AddOrGetExisting(String, Object, DateTimeOffset, String) method overload returns an object value, not a CacheItem object.

AddOrGetExisting(String, Object, CacheItemPolicy, String) AddOrGetExisting(String, Object, CacheItemPolicy, String) AddOrGetExisting(String, Object, CacheItemPolicy, String)

在派生类中重写时,向缓存中插入缓存项,并指定该缓存项的键和值以及有关如何逐出该项的信息。When overridden in a derived class, inserts a cache entry into the cache, specifying a key and a value for the cache entry, and information about how the entry will be evicted.

public abstract object AddOrGetExisting (string key, object value, System.Runtime.Caching.CacheItemPolicy policy, string regionName = null);
abstract member AddOrGetExisting : string * obj * System.Runtime.Caching.CacheItemPolicy * string -> obj
Public MustOverride Function AddOrGetExisting (key As String, value As Object, policy As CacheItemPolicy, Optional regionName As String = null) As Object

参数

key
String String String String

该缓存项的唯一标识符。A unique identifier for the cache entry.

value
Object Object Object Object

要插入的对象。The object to insert.

policy
CacheItemPolicy CacheItemPolicy CacheItemPolicy CacheItemPolicy

一个包含该缓存项的逐出详细信息的对象。An object that contains eviction details for the cache entry. 此对象提供比简单绝对过期更多的逐出选项。This object provides more options for eviction than a simple absolute expiration.

regionName
String String String String

可选。Optional. 缓存中的一个可用来添加缓存项的命名区域(如果实现了区域)。A named region in the cache to which the cache entry can be added, if regions are implemented. 可选参数的默认值为 nullThe default value for the optional parameter is null.

返回

如果存在具有相同键的缓存项,则为指定缓存项的值;否则为 nullIf a cache entry with the same key exists, the specified cache entry's value; otherwise, null.

注解

AddOrGetExisting(String, Object, CacheItemPolicy, String)方法返回一个对象值,而不CacheItem对象。The AddOrGetExisting(String, Object, CacheItemPolicy, String) method returns an object value, not a CacheItem object.

适用于