MemoryCache::Set Method (String, Object, CacheItemPolicy, String)
Inserts a cache entry into the cache by using a key and a value and eviction.
Assembly: System.Runtime.Caching (in System.Runtime.Caching.dll)
public: virtual void Set( String^ key, Object^ value, CacheItemPolicy^ policy, String^ regionName ) override
Parameters
- key
- Type: System::String
A unique identifier for the cache entry to insert.
- 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. This parameter is nullptr by default, because the MemoryCache class does not implement regions.
| Exception | Condition |
|---|---|
| ArgumentNullException | key is nullptr. -or- value is nullptr -or- The callback reference that was passed to the helper method in the UpdateCallback property is nullptr. |
| ArgumentException |
|
| 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 property is not a value of the CacheItemPriority enumeration. |
| NotSupportedException | regionName is not nullptr. |
Like other Set method overloads, the Set method always puts a cache value in the cache, regardless whether a matching entry already exists. If the specified entry does not exist in the cache, a new cache entry is inserted. If the specified entry exists, it is updated.
Removing an entry triggers any associated change monitors. If the removed item was associated with a CacheItemUpdateCallback object or CacheItemRemovedCallback object, the reason for removal that is passed to the callbacks is contained in the Removed property.
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.