Caching in ASP.Net
When you store most frequently used data on to the temporary storage
and providing to different clients request, then it is called as caching.
The main advantage of caching is to
improve the performance of the web server by reducing the processing time.
When you are expecting more no. of
requests to a web page within a particular time interval, also the web page is
having database interaction and the data within the database is not changing
frequently then apply the caching.
ASP 3.0 supports, entire page caching only at client side.
ASP.Net supports 3 types of caching,
a. Output Caching (Entire
page Caching)
b. Fragment Caching (Portion of web Page as Caching)
b. Fragment Caching (Portion of web Page as Caching)
c. Data Caching (memory
Variable Caching)
Output caching is also termed
as entire page caching.
When you want to maintain multiple
buffers content towards a single web page then we require varybyparam option.
To achieve this output caching go
to html view,
<%@ outputcache
duration=”seconds” varybyparam=”none”%>
User defined control.
Web user control will provide
reusability of graphical interfaces and coding.
It will compile dynamically along
with web page.
The extension of the file is .ascx
This is local to the application,
so it will not appear in the toolbox.
Caching can be applied to web user
control.
When you want to make use of web
user control within a web page then .ascx file has to be registered with the
web page.
i.e. under html view,
<%@ Register
TagPrefix="uc1" TagName="WebUserControl1"
Src="WebUserControl1.ascx"%>
A web user control is similar to webform
but can’t be called independently.
It has to be contained by web form.
When you apply caching on a portion
of web page then it is called as fragment caching. This can be achieved
under web user control.
Data caching
When you apply caching on the
memory variables, then it is called as data caching. This can be classified
into three types.
1.
Ordinary caching
2.
File based dependency data
caching
3.
Time based dependency data
caching
In asp.net the alternative for
application memory is provided with data caching.
This will overcome all the
drawbacks of application memory variable like,
1. Data caching is a thread safe as
compared to application memory.
So the lock method will be applied
implicitly to the variable, which is used for modification.
Application. Lock ()
Application. Unlock ()
(Not required in case of caching)
2. Data caching supports expiry
policy for the data, which is not supported by application memory variable.
System.web.caching (namespace)
Cache class
CacheDependency Class
Ordinary data caching
Cache. Insert (“A”, 100)
Or
Cache (“A”) = 100
File based dependency data
caching
When you want to provide expiry
policy of data, based on time stamp of the file, then it is called as file
based dependency data caching.
Time based dependency data
caching
When you want to provide expiry
policy of data, based on time, then it is called as time based dependency data
caching.
Time can be based on two types.
1.
Absolute time will be
considered from storage time.
2.
Sliding time will be considered
from the last access.
When it comes to data caching, the
content will be erased, when application demands for the memory.
No comments:
Post a Comment