Saturday, 22 March 2014

what is caching in asp.net ?

Caching in C# means temporary storage of data in memories that is highly demanding and frequently use in order to accelerate performance and quick access to the various essential information.
Why Caching: - Greater advantage is to reduce repeated calls to the database for information.
We can achieve caching in ASP.Net in three ways:

1. Page level output caching : it can achieve by simple tag changes on output directory; Caching the output page, in cache of subsequest request it served from cache.
<%@ OutputCache Duration="second" VaryByParam="parametername" %>

2. Fragment caching :  User control caching, it is useful when most of the content of the page doesn’t change or change often  .
If the specific part of page content changes we don’t need to cache entire page, instead of we can cache parts that are constant across each and every session.
Fragment caching uses same syntax as page level out put caching, but applied to a user control (.ascx page) instead of webform.

3.  Caching API :  API Caching using the cache object. The cache object are used to store any serializable data object with the facility to specify the cache expiration. We can use the cache object share the same object across the related page.
In ASP.Net data caching is mainly done by using three classes System.Web, System.Web.Cache & System.Web.CacheDependency
System.Web.Cache  : Cache object is used to add or removed cache object from cache.
System.Web.CacheDependency : Cache dependency object is used to specify the dependency to cache object.
a.       Add into cache.
Cache["key"] = "123456";
b.      Get value from cache
str = Convert.ToString(Cache["key"]);
c.       Remove from cache.
Cache.Remove("key");

No comments:

Post a Comment