Friday, December 23, 2011

DataCaching in asp.net

All caching concepts are application based and Every user can access the content.Any type of caching will result in separate storage at server and awards processing of data of Request .Data Caching is implemented using asp.net cache object.Cache object are self locking objects and there are no of methods to explicitly log them.Cache objects lock specific accessed content but not the entire cache data.Cache objects can be created based on time which means after the time elapses the object will expired(like page output cache)
Another important  feature of cache objects is dependency based on expiry in this model we can create cache object based on a resource and if the resource is modified then cache object will expire

Before going to example we have to know what is Application variable.If you have more application variable they can reduce the performance.Cache is self locking object ,no locking by user.Here i will show how to use cache object in application.For this i have taken a form with label,button and grid view

Example Code behind:
if(cache(dsdata==null)
  {
   ds=DataHelper.GetData("select*from emp");
    cache["dsdata"]=ds;
  }
   lbl.Text="from database";
else
  {
   ds=(Dataset)Cache["dsdata"];
   lbl.Text="From Cache";
  }
gvemp.DataSource=ds.Tabe[0];
gvemp.DataBind();
Note:Cache objects are any cache is maintained by run time not by user
Post a Comment

Bel