Caching is a technique that temporarily stores valuable information in server memory so it can be reused.
Caching is often used to store information that's retrieved from a database, so they'll retrieve the information directly from server memory which is a much faster proposition instead of database connection and running query.
The right time to use Caching:
A good caching strategy identifies the most frequently used pieces of data that are the most time consuming to create, and stores them.
- cache data (or web pages) that are expensive--> which uses database or file connection.
- cache data (or web pages) that are used frequently
Caching types in ASP.Net
- Output caching-->it stores a copy of the final rendered HTML page that is sent to the client, so when client require the same page, the page isn't executed again and send directly to client.
- fragment caching --> instead of caching the HTML for the whole page, it allows you to cache the HTML for a portion of it (like caching user control of certain page)
- Data source caching --> caching that's built into the data source controls including the SqlDataSource, ObjectDataSource and XmlDataSource. you simply configure the properties and the data source control manages the caching storage and retrieval.
BUT NOTE THAT:
Using data caching is conceptually the same as using application state but it is much more server friendly because items will be removed from the cache automatically when it grows too large and performance could be affected.
**TRY Output Caching...
you have two alternatives to carry out output caching
1. insert outputcache directive at the top to .aspx page
%@ OutputCache Duration="20" VaryByParam="None" %
* Duration paramter: it is duration which asp.net will cache the page in seconds
2. caching page at client side by insert the outputcache directive with location attribute location = "client"
%@ OutputCache Duration="20" VaryByParam="None" Location="Client" %
*browser caches the page at client side, and client can get it by retype the same link or back to the page but if the client refresh the page, the page will be abandoned and the page will be reqested again from the server.
*can be useful technique if your cached page uses some sort of personalized data. even though each user is in a separate session, the page will be created only one and reused for all clients ensuring that most will receive the wrong greeting.
if the page is receiving information from another page through the query string
*VaryByParam="None" --> tells ASP.Net that ou need to store only one copy of the cached page which is suitable for al scenarios
*VaryByParam="*" --> to indicate that the page uses the query string and to instruct ASP.Net to cache separate copies of the page for different query string arguments (i.e. ASP.Net will examine the query string. if the string matches a previous request and a cached copy of that page exists, it will be reused)
*VaryByParam="ProductID" && VaryByParam="ProductID;CurrencyType" --> ASP.Net will examine the query string, looking for the ProductID parameter. Requests with different ProductID parameters wil be cached separatelym but all other parameters will be ignored.
i will working on my next blogs to complete full image of ASP.Net Caching methdology to get better web applications performance... any feedback will be welcome......... :D
