Redigera

Dela via


ObjectCache.AddOrGetExisting Method

Definition

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.

Overloads

AddOrGetExisting(CacheItem, CacheItemPolicy)

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.

Remarks

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. The cache entry can be a CacheItem object or a generic object.

There is one difference between the AddOrGetExisting overloads and the Add overloads. 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. The Add overloads do not.

AddOrGetExisting(CacheItem, CacheItemPolicy)

Source:
ObjectCache.cs
Source:
ObjectCache.cs
Source:
ObjectCache.cs

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

Parameters

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.

Returns

If a cache entry with the same key exists, the specified cache entry; otherwise, null.

Applies to

AddOrGetExisting(String, Object, DateTimeOffset, String)

Source:
ObjectCache.cs
Source:
ObjectCache.cs
Source:
ObjectCache.cs

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

Parameters

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. The default value for the optional parameter is null.

Returns

If a cache entry with the same key exists, the specified cache entry's value; otherwise, null.

Remarks

This AddOrGetExisting(String, Object, DateTimeOffset, String) method overload returns an object value, not a CacheItem object.

Applies to

AddOrGetExisting(String, Object, CacheItemPolicy, String)

Source:
ObjectCache.cs
Source:
ObjectCache.cs
Source:
ObjectCache.cs

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

Parameters

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. The default value for the optional parameter is null.

Returns

If a cache entry with the same key exists, the specified cache entry's value; otherwise, null.

Remarks

The AddOrGetExisting(String, Object, CacheItemPolicy, String) method returns an object value, not a CacheItem object.

Applies to