1.

What is Data Caching?

Answer»

ASP.NET ADDITIONALLY supports the caching of information as objects. We can store objects in memory and use them crosswise over different PAGES in our application. This element is actualized utilizing the Cache class. This cache has a lifetime equal to that of the application. Objects can be PUT away as name-value pairs in the cache. A string can be embedded into the cache as pursues:

Cache["name"]="Dhruv";

The cached string value can be fetched like this:

if (Cache["name"] != null) Labe12.Text= Cache["name"].ToString();

To embed objects into the Cache, the Add() or various forms of the Insert() of the Cache class can be utilized. These methods enable us to utilize the more dominant features GIVEN by the Cache class. One of the over-burdens of the Insert method is utilized as pursues:

Cache.Insert("Name", strName, new CacheDependency(Server.MapPath("name.txt"), DateTime.Now.AddMinutes(2), TimeSpan.Zero);

The initial two parameters are the key and the object to be embedded. The third parameter is of sort CacheDependency and encourages us to set a reliance on this value to the document named name.txt. So at whatever point this document changes, the value in the cache is expired. We can mention NULL to show no dependency on this. The fourth parameter indicates the time at which the value ought to be deleted from the cache. The last parameter is the SLIDING expiration parameter which demonstrates the time interim after which the object is to be expelled from the cache after this time.

The cache consequently expels the least utilized things from memory, when framework memory turns out to below. This procedure is called scavenging. We can mention priority for the objects that are added to cache so that those few things are given more importance than others:

Cache.Insert("Name", strName, new CacheDependency(Server.MapPath("name.txt"), DateTime.Now.AddMinutes(2), TimeSpan.Zero, CacheItemPriority.High, null);

The CacheItemPriority sets the priority level to an item. The CacheItemPriority.High allocates a high-level priority to an item with the goal that this is most drastically averse to be erased from the store.



Discussion

No Comment Found