Just another WordPress.com weblog

Caching is a feature of ASP.NET that improves the performance of web applications by minimizing the usage of server resources to a great extent.Caching is a feature that stores data in local memory, allowing incoming requests to be served from memory directly.

Types of Caching

Caching in ASP.NET can be of the following types

  • Page Output Caching – Caches the output from an entire page and returns it for future requests instead of re-executing the requested page Eg: <%@OutputCache Duration=”30″ VaryByParam=”none” %>
  • Page Fragment Caching – Caches just a part of a page which can then be reused even while other parts of the page are being dynamically generated     Eg : <%@ OutputCache Duration=”15″ VaryByControl=”EmpID;DeptID” VaryByParam=”*”%>
  • Data Caching – Programmatically caches arbitrary objects for later reuse without re-incurring the overhead of creating them. Eg….
public DataSet GetUserInfo()
{   
  string cacheKey = "UserInfo";   
  DataSet ds = Cache[cacheKey] as DataSet;   
  if (ds == null)   
 {     
   ds = GetUserInfoFromDatabase();     
   Cache.Insert(cacheKey, ds, null, NoAbsoluteExpiration,       
   TimeSpan.FromHours(15),CacheItemPriority.High, null);   
}      
return ds;
}   

DataSet GetUserInfoFromDatabase() {
// Usual code to populate a data set from thedatabase. This data set
// object is then returned.
}

Benefits of Caching

The following are the benefits of using Caching

  • Faster page rendering
  • Minimization of database hits
  • Minimization of the consumption of server resources
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Tag Cloud

%d bloggers like this: