NCache 4.6 - Online Documentation

Updating Data with Sliding Expiration

 
In the following example, the insert operation is used to add/update a Sliding Expiration time period to an item already added to NCache. The expiration time period is set by using the TimeSpan class. Also if the Sliding Expiration method is being used, NoAbsoluteExpiration needs to be explicitly declared in the parameters.
 
      To utilize the API, include the following namespace in your application: Alachisoft.NCache.Web.Caching.
 
            try
            {
                //updating sliding expiration of 5 min through Insert API.
                cache.Insert(key, product, null, Cache.NoAbsoluteExpiration,new TimeSpan(0, 5, 0), CacheItemPriority.Default);
 
                //updating Default Sliding expiration with configured value
                cache.Add(key, product, null, Cache.NoAbsoluteExpiration, Cache.DefaultSliding, CacheItemPriority.Default);
 
                //updating SlidingLonger expiration with configured value
                cache.Add(key, product, null, Cache.NoAbsoluteExpiration, Cache.DefaultSlidingLonger, CacheItemPriority.Default);
            }
            catch(Exception ex)
            {
                // handle exception
            }
 
 
 
See Also