This documentation is archived and is not being maintained.

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.

Namespace:  System.Runtime.Caching
Assembly:  System.Runtime.Caching (in System.Runtime.Caching.dll)

public:
virtual void Set(
	CacheItem^ item, 
	CacheItemPolicy^ policy
) override

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.

ExceptionCondition
ArgumentNullException

item is nullptr.

-or-

The Key property is nullptr.

-or-

The Value property is nullptr.

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.

.NET Framework

Supported in: 4

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.
Show: