Thursday, 30 January 2014

Caching Absolute and Sliding

Absolute Expiration: A DateTime Object that specifies when the data should be removed from the cache.Whe you specify "Absolute Expiration",the cache item will expire at that time,irrecspective of whether the acached tem is access or not.
(In Short It will be expired after given time automatically);

Sliding Expiration:A TimeSpan object that idetfies how long the data should remain in the cache after was last accessed..
(In Short It will remain in cache from the time of last accessed)

Absolute and Sliding Expiration can not be used together.

1. Using "Cache" object's Insert() method

Example : Cache.Insert("KeyName", DATAFORCACHE);

2. Using "Cache" object's Add() method

Example: Cache.Add(""KeyName"", DATAFORCACHE, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null);

CacheItemPriority enum values:

1) CacheItemPriority.Low
2) CacheItemPriority.BelowNormal
3) CacheItemPriority.Normal
4) CacheItemPriority.Default
5) CacheItemPriority.AboveNormal
6) CacheItemPriority.High
7) CacheItemPriority.NotRemovable

No comments:

Post a Comment