Sunday 6 May 2012

Cache

Namespace: System.Web.Caching

<Properties>
Count: Gets the number of items stored in the cache
EffectivePercentagePhysicalMemoryLimit:
Item: Gets or sets the cache item at the specified key

<Methods>
Add: adds the specified item to the Cache object with dependencies, expiration and priority policies
Get: retrieves the specified item from the Cache object
GetHashCode: Serves as a hash function for a particular type.
Insert(String, Object): inserts an item into the Cache object with a cache key




To use the CacheItemRemovedCallback delegate, you must add an item to the cache with this method, so that ASP.NET can automatically make the proper method calls when the item is removed. (look at red under line in above picture).

<Cache vs Session Variables>


Cache is application specific and Session is user specific.
eg. If you have a cache object say Cache["abc"], then this value is available to all the user logged in to the site.
Cache["abc"]= "website cache";
User A reads its value as "website cache"
User B reads its value as "website cache"
But if you have session variable, then each user has its own copy of Session.
eg. User A --> Session["UserName"]= "Mr. XYZ";
User B --> Session["UserName"]="Mr. ABC"; 

No comments:

Post a Comment