| Caching in ASP.Net |
| |
| Expiration |
| |
| ASP.NET automatically removes items from the cache when they expire. When adding an item to the cache, you can set its expiration in two ways as described in the following table. |
| |
| Absolute Expiration |
| |
| This specifies that an item expires at a set time, regardless of how often it is accessed. For absolute expiration, an absolute time period is defined after which the item will be expired from the cache in any case. |
| |
| For example, you can set an item to expire at 6:00 PM or after four hours. |
| |
| Cache.Insert ("mykey ", value, Nothing, Now.AddSeconds(20), Cache.NoSlidingExpiration, CacheItemPriority.High, Nothing) |
| |
| Sliding expiration |
| |
| This specifies how long after an item was last accessed that it expires. For sliding expiration, a time span is defined. If the item is not used in that time span then it will be removed from the cache else it will again occupy the cache for the next time span whenever used. |
| |
| For example, you can set an item to expire 20 minutes after it was last accessed in the cache. |
| |
Cache.Insert("mykey", value, Nothing, Cache.NoAbsoluteExpiration,
TimeSpan.FromSeconds(20),
CacheItemPriority.High, Nothing) |
| |
|
| |