ObjectCache.AddOrGetExisting 方法
定义
在派生类中重写时,尝试向缓存中插入缓存项,并返回具有匹配键的现有缓存项。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) |
在派生类中重写时,向缓存中插入指定的 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) |
在派生类中重写时,通过使用键、表示缓存项的对象、绝对过期值和要添加缓存的可选区域,向缓存中插入缓存项。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) |
在派生类中重写时,向缓存中插入缓存项,并指定该缓存项的键和值以及有关如何逐出该项的信息。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)
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
要插入的对象。The object to insert.
- policy
- CacheItemPolicy
一个包含该缓存项的逐出详细信息的对象。An object that contains eviction details for the cache entry. 此对象提供比简单绝对过期更多的逐出选项。This object provides more options for eviction than a simple absolute expiration.
返回
如果存在具有相同键的缓存项,则为指定的缓存项;否则为 null。If a cache entry with the same key exists, the specified cache entry; otherwise, null.
适用于
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 = default);
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 = Nothing) As Object
参数
- key
- String
该缓存项的唯一标识符。A unique identifier for the cache entry.
- value
- Object
要插入的对象。The object to insert.
- absoluteExpiration
- DateTimeOffset
缓存项的固定的过期日期和时间。The fixed date and time at which the cache entry will expire.
- regionName
- String
可选。Optional. 缓存中的一个可用来添加缓存项的命名区域(如果实现了区域)。A named region in the cache to which the cache entry can be added, if regions are implemented. 可选参数的默认值为 null。The default value for the optional parameter is null.
返回
如果存在具有相同键的缓存项,则为指定缓存项的值;否则为 null。If 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)
在派生类中重写时,向缓存中插入缓存项,并指定该缓存项的键和值以及有关如何逐出该项的信息。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 = default);
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 = Nothing) As Object
参数
- key
- String
该缓存项的唯一标识符。A unique identifier for the cache entry.
- value
- Object
要插入的对象。The object to insert.
- policy
- 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
可选。Optional. 缓存中的一个可用来添加缓存项的命名区域(如果实现了区域)。A named region in the cache to which the cache entry can be added, if regions are implemented. 可选参数的默认值为 null。The default value for the optional parameter is null.
返回
如果存在具有相同键的缓存项,则为指定缓存项的值;否则为 null。If 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.