NCache 4.6 - Online Documentation

Adding New Item with Sliding Expiration

 
In the following example, the Add Operation is used in NCache to add a new item with the Sliding Expiration time period defined. 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
        {
            // adding sliding expiration of 5 min through Add API.
            cache.Add(key, product, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 5, 0), CacheItemPriority.Default);
 
            // adding Default Sliding expiration with configured value
            cache.Add(key, product, null, Cache.NoAbsoluteExpiration, Cache.DefaultSliding, CacheItemPriority.Default);
 
            // adding SlidingLonger expiration with configured value
            cache.Add(key, product, null, Cache.NoAbsoluteExpiration, Cache.DefaultSlidingLonger, CacheItemPriority.Default);
        }
        catch (Exception ex)
        {
            // handle exception
        }
 
 
See Also