Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between Sliding and Absolute Expiration?

    • 0
    • 1
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 1.50k
    Comment on it

    Sliding and Absolute Expiration

    The performance of an application can be increased by reducing the round trips made by server to database. This performance enhancement can be achieved by using asp.net cache. For using asp.net cache, cache object is created for caching data. This cached data has expiration time such that cached data expire after defined time and fresh data then put into cache. This is time base expiration.


    Time base expiration are of two types:

     

    Absolute Expiration :-

     

    • The cache is expired after a certain time period from the time of activating cache.
    • The cache will expire during that time period. It does not take account whether request for cache was made or not during that time period.
    • This type of expiration is helpful when there is no frequent change in cached data.

     

    Sliding Expiration

     

    • The cache is expired after a certain time period from the time of activating cache.
    • The expiration time is increased if cache is accessed during expiration time. Thus expiration of cache depends on accessibility of cache.
    • This type of expiration is helpful when there is large amount of data in cache i.e frequently used data in application is put in cache. 

     

    Following is the method used for inserting cache object into cache. This method has fields for dependencies and expiration policies.  

     

    Cache.Insert Method (String,Object,CacheDependency,DateTime,TimeSpan)


      

    Example of Absolute Expiration:

     

    Cache.Insert("AbsoluteExpiration", cacheData, null,DateTime.Now.AddMinutes(4), System.Web.Caching.Cache.NoSlidingExpiration);

     

    In above example "cacheData" is inserted into cache. The "cacheData" will expire after 4 minutes no matter it was accessed or not. 

    Example of Sliding Expiration:

     

    Cache.Insert("SlidingExpiration", cacheData, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(4));

     

    In above example "cacheData" is inserted into cache. The cacheData will expire after 4 minutes if "cacheData" was not accessed within 4 minutes otherwise in case of accessibilty time expiration period increases.

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: