An application can increase performance by storing data that is accessed
frequently and require significant time to create.
Instead of recreating same data, satisfying request with stored data in sub
sequent requests, this technique is called Caching.
Application cache
Provides a way to store application data in pair of key \ value. This stored
data is volatile, it removes as it expire or become invalidate. Application can
be configure to notify when an item remove from caching.
Pattern is that any time you access an item from cache you checks whether
it exist or not, if not you can recreate it and place it to cache, this pattern
ensures that cache contained latest data.
Adding value to cache
Cache.Insert("Name", strName,
new CacheDependency(Server.MapPath("name.txt"),
DateTime.Now.AddMinutes(2), TimeSpan.Zero);
Accessing cached value
if (Cache["name"] != null) Label1.Text= Cache["name"].ToString();
Page output cache
It stores processed page / user control in cache. This allows asp.net to send
response to client without processing page again.
This technique can increase performance of page dramatically. You can use
it for a page that has high traffic and not updated frequently.
Full page can be cached by putting below tag to the page
By specifying on page this will cache the page for 60 seconds.
<%@ OutputCache Duration="60" VaryByParam="none" %>
There are two divisions types of page output cache
1. Control caching(Fragment caching)
2. Post-cache substitution
1. Control caching(Fragment caching) - You can mark a particular section as
cacheable like user control, so whole page recreated dynamically every time
accept marked cacheable area.
Specifying this will cache the complete user control in wich you define it
<%@ OutputCache Duration="60" VaryByControl="ControlID" %>
Ex. Share stock display page, displays weekly summary also then make user
control for weekly summary and mark that cacheable.
2. Post-cache substitution - You can mark a particular section as non cacheable,
so whole page cached but marked section recreated dynamically each time page
requested.
we can achieve this by using substitution control, this control is used for this
purpose generally. we assign 'MethodName' attribute of this tag by a method that
returns a string.
<asp:Substitution ID="Substitution1" runat="server" MethodName="getScore" />
Ex.
1. Live cricket score page, area / user control that displaying score can be marked
as non cacheble, so every time it will recreated and whole page come from cache.
2. If you have a static page that has a label that displays name of page requester
then you can mark that label non cacheable, so whole page will cached and label
recreated dynamically each time.
ASP.NET can remove data from the cache for one of these reasons:
1. Because memory on the server is low, a process known as scavenging.
2. Because the item in the cache has expired.
3. Because the item's dependency changes.
Read page on below link http://msdn.microsoft.com/en-us/library/aa478965.aspx
frequently and require significant time to create.
Instead of recreating same data, satisfying request with stored data in sub
sequent requests, this technique is called Caching.
Application cache
Provides a way to store application data in pair of key \ value. This stored
data is volatile, it removes as it expire or become invalidate. Application can
be configure to notify when an item remove from caching.
Pattern is that any time you access an item from cache you checks whether
it exist or not, if not you can recreate it and place it to cache, this pattern
ensures that cache contained latest data.
Adding value to cache
Cache.Insert("Name", strName,
new CacheDependency(Server.MapPath("name.txt"),
DateTime.Now.AddMinutes(2), TimeSpan.Zero);
Accessing cached value
if (Cache["name"] != null) Label1.Text= Cache["name"].ToString();
Page output cache
It stores processed page / user control in cache. This allows asp.net to send
response to client without processing page again.
This technique can increase performance of page dramatically. You can use
it for a page that has high traffic and not updated frequently.
Full page can be cached by putting below tag to the page
By specifying on page this will cache the page for 60 seconds.
<%@ OutputCache Duration="60" VaryByParam="none" %>
There are two divisions types of page output cache
1. Control caching(Fragment caching)
2. Post-cache substitution
1. Control caching(Fragment caching) - You can mark a particular section as
cacheable like user control, so whole page recreated dynamically every time
accept marked cacheable area.
Specifying this will cache the complete user control in wich you define it
<%@ OutputCache Duration="60" VaryByControl="ControlID" %>
Ex. Share stock display page, displays weekly summary also then make user
control for weekly summary and mark that cacheable.
2. Post-cache substitution - You can mark a particular section as non cacheable,
so whole page cached but marked section recreated dynamically each time page
requested.
we can achieve this by using substitution control, this control is used for this
purpose generally. we assign 'MethodName' attribute of this tag by a method that
returns a string.
<asp:Substitution ID="Substitution1" runat="server" MethodName="getScore" />
Ex.
1. Live cricket score page, area / user control that displaying score can be marked
as non cacheble, so every time it will recreated and whole page come from cache.
2. If you have a static page that has a label that displays name of page requester
then you can mark that label non cacheable, so whole page will cached and label
recreated dynamically each time.
ASP.NET can remove data from the cache for one of these reasons:
1. Because memory on the server is low, a process known as scavenging.
2. Because the item in the cache has expired.
3. Because the item's dependency changes.
Read page on below link http://msdn.microsoft.com/en-us/library/aa478965.aspx
No comments:
Post a Comment