Adding Item to Cache Set
suggest changeThe Set method inserts a cache entry by using a CacheItem to supply the key and value.
This method overrides ObjectCache.Set(CacheItem, CacheItemPolicy).
private static void SetToCache()
{
string key = "Cache_Key";
string value = "Cache_Value";
// Get a reference to the default MemoryCache instance.
var cacheContainer = MemoryCache.Default;
var policy = new CacheItemPolicy()
{
AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(DEFAULT_CACHE_EXPIRATION_MINUTES)
};
var itemToCache = new CacheItem(key, value); // Value is of type object.
cacheContainer.Set(itemToCache, policy);
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents