MemoryCache::Set Method (CacheItem^, CacheItemPolicy^)
Inserts a cache entry into the cache by using a CacheItem instance to supply the key and value for the cache entry.
Assembly: System.Runtime.Caching (in System.Runtime.Caching.dll)
Parameters
- item
-
Type:
System.Runtime.Caching::CacheItem^
An object that represents a cache entry to insert.
- 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.
| Exception | Condition |
|---|---|
| ArgumentNullException | |
| ArgumentException | An invalid combination of arguments for the cache entry was passed. This occurs if the following expiration details are set on the policy object for the cache entry:
|
| ArgumentOutOfRangeException | The SlidingExpiration property is set to a value less than Zero. -or- The SlidingExpiration property is set to a value greater than one year. -or- The Priority is not a value of the CacheItemPriority enumeration. |
Like other Set method overloads, the Set method always puts a cache value in the cache, regardless whether an entry already exists that has the same key. If the specified entry does not exist in the cache, a new cache entry is inserted. If the specified entry already exists, its value is updated.
Available since 4.0