NCache 4.6 - Online Documentation

Setting Sliding Expiration with CacheItem

 
In the following example, Sliding Expiration time period is set by assigning it as a property of a CacheItem object in NCache.
 
      To utilize the API, include the following namespace in your application: Alachisoft.NCache.Web.Caching.
 
 
        // Setting sliding expiration of 10 seconds.
        cacheItem.SlidingExpiration = new TimeSpan(0, 0, 10);
 
        string key = "Product:" + product.ProductID;
 
        try
        {
            cache.Add(key, cacheItem, DSWriteOption.None, null);
        }
        catch (Exception ex)
        {
            // handle exception
        }
 
 
See Also