Adding Item to Cache Set

suggest change

The 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);
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents