ASP.NET STATE MANAGEMENT
SERVER SITE STATE MANAGEMENT
• In asp.net server site Speed is a critical factor that judges success or failure of any website.
• When multiple users access a website simultaneously, access to web pages becomes slow.
• This problem of slow access can be solved by using caching.
• Caching improves performance of web app by temporarily storing frequently used web objects, such as HTML pages, on local hard disks, for later retrieval.
• So the Web server processes the request for the first time only and caches the requests for future, ie, subsequent requests are processed from cache instead of web server.
• This leads to considerable reduction in the load on the server.
TYPE OF CACHING
There are four type of caching
1. Page Output Caching /Output Caching
2. Partial Page Caching / Fragment caching
3. Data Caching
1) PAGE OUTPUT CACHING
• It improves performance of asp.net web app by caching rendered markup of asp.net web page, thereby saving database access and page rendering time.
• When the user requests the same page within a specified time period, instead of re-rendering the page, asp.net serves the cached page to the user.
• Output caching is useful when the content of the Web page changes rarely.
• To implement output caching, insert the @OutputCache directive at the top of the .aspx file, just below @Page directive:
<%@ OutputCache Duration=“20” VaryByParam=“None” %>
• Duration attribute instructs asp.net runtime to cache the page for the specified number of seconds.
• VaryByParam attribute specifies how many copies of the page need to be saved. When it is set to none, it indicates only once copy of the page is to be cached.
2) FRAGEMENT CACHING / PARTIAL PAGE CACHING
• Data from specific sections of the page is cached.
• Used only when a portion of the web page needs to be cached, since it doesn’t change frequently. The remaining content of the page is loaded dynamically.
• To implement fragment caching, the portion of the page that is to be cached is encapsulated in a user control, and then the @OutputCache directive is added to the control.
3) DATA CACHING
• It is used to store frequently used data in the built-in collection object called Cache
• Cache is the property of the Page class and it returns the instance of System.Web.Caching.Cache class
• Cache object works like Application object.
• It is globally available to all requests from all clients
• For each user, a web application can be personalized.
• This is done by storing and using information that is unique to a user.
• A user visits a website for online shopping of books (Like amazon.com), to purchase books from IT category.
• This info can be stored as a profile property for that user.
• When the same user visits the website again, info stored in the profile properties can be sued to display the lates books in IT category to the user.
• User preferences can be stored using Profiles, without writing much code.
• These preferences are stored as named properties in profiles.
• The preferences can be stored in the form of:
a)Simple data types,
b)Complex data structures, or
.NET framework classes
For Share :-