MemoryCache::AddOrGetExisting Method (String, Object, CacheItemPolicy, String)
Inserts a cache entry into the cache using the specified key and value and the specified details for how it is to be evicted.
Assembly: System.Runtime.Caching (in System.Runtime.Caching.dll)
public: virtual Object^ AddOrGetExisting( String^ key, Object^ value, CacheItemPolicy^ policy, String^ regionName ) override
Parameters
- key
- Type: System::String
A unique identifier for the cache entry to add or get.
- value
- Type: System::Object
The data for the cache entry.
- policy
- Type: System.Runtime.Caching::CacheItemPolicy
An object that contains eviction details for the cache entry. This object provides more options for eviction than a simple absolute expiration.
- regionName
- Type: System::String
A named region in the cache to which a cache entry can be added. Do not pass a value for this parameter. By default, this parameter is nullptr, because the MemoryCache class does not implement regions.
Return Value
Type: System::ObjectIf a matching cache entry already exists, a cache entry; otherwise, nullptr.
| Exception | Condition |
|---|---|
| ArgumentNullException | key is nullptr. |
| ArgumentNullException | value is nullptr. |
| ArgumentException | Both the absolute and sliding expiration values of CacheItemPolicy object are set to values other than the defaults of InfiniteAbsoluteExpiration and NoSlidingExpiration. The MemoryCache class cannot set expiration policy based on a combination of both an absolute and a sliding expiration. Only one expiration setting can be explicitly set when you use the MemoryCache class. The other setting must be set to InfiniteAbsoluteExpiration or NoSlidingExpiration. -or- Both the removal callback and the update callback have been specified for CacheItemPolicy. The MemoryCache only supports using one type of callback per cache entry. |
| ArgumentOutOfRangeException | The SlidingExpiration property is set to a value less than Zero. -or- The SlidingExpiration has been set to a value greater than one year. -or- The Priority property is not a value of the CacheItemPriority enumeration. |
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.