Monday, June 24, 2013

Asp.Net Cache

Asp.Net provides a caching mechanism which can be used to store data in a key value format. The data stored in the Asp.Net Cache can be retrieved at any time by using the key against which the value is stored.

The following example stores the list of countries is a Cache variable “cacheCountryList”. using System.Web.Caching;
 List lstCountry = (List)Cache[“cacheCountryList”];
 if (lstCountry == null)
 {   
         // Load Countries List from DB & put add it to the Cache
         lstCountry  = GetCountryListFromDb();
         Cache.Insert(“cacheCountryList”, lstCountry);
}

In the above example we are trying to get the list of countries from the cache, if the Cache is null, then we do a call to the database to get the countries from the database, also we refill the cache with the data obtained from the database, so that the cache can be used the next time when a request wants to get the list of countries.


Search Flipkart Products:
Flipkart.com

No comments: