Monday 16 June 2014

State Management Techniques- Part 2

  1. QueryString
  2. Cookies
Cache:
ASP.NET has taken some dramatic steps forward with caching. Many developers who first learn about caching see it as a bit of a frill, but nothing could be further from the truth. Used intelligently, caching could provide a twofold, threefold, or even tenfold performance improvement by retaining important data for just a short period of time.ASP.NET really has two types of caching. Your applications can and should use both types, because they complement each other.

Output caching: 
This is the simplest type of caching. It stores a copy of the final rendered HTML page that is sent to the client. The next client that submits a request for this page doesn’t actually run the page. Instead, the final HTML output is sent automatically.The time that would have been required to run the page and its code is completely reclaimed.

Data caching:
This is carried out manually in your code. To use data caching, you store important pieces of information that are time-consuming to reconstruct (such as a DataSet retrieved from a database) in the cache. Other pages can check for the existence of this information and use it, thereby bypassing the steps ordinarily required to retrieve it. Data caching is conceptually the same as using application state, but it’s much more server-friendly because items will be removed from the cache automatically when it grows too large and performance could be affected. Items can also be set to expire automatically.

Fragment caching:
This is a specialized type of output caching—instead of caching the HTML for the whole page, it allows you to cache the HTML for a portion of it. Fragment caching works by storing the rendered HTML output of a user control on a page. The next time the page is executed, the same page events fire (and so your page code will still run), but the code for the appropriate user control isn’t executed.

Data source caching:
This is the caching that’s built into the data source controls, including the SqlDataSource, ObjectDataSource, and XmlDataSource. Technically,data source caching uses data caching. The difference is that you don’t need to handle the process explicitly. Instead, you simply configure the appropriate properties, and the data source control manages the caching storage and retrieval

Output caching: Output Caching has following attributes

1. Duration: The attribute is the time, indicates how long (in seconds) the page will be cached.

















2. VaryByCustom:  Any text that represents custom output caching requirements. If this attribute is given a value of browser, the cache is varied by browser name and major version information. If a custom string is entered, you must override theGetVaryByCustomString method in your application's Global.asax file.















Note: Run ASP.NET web application and launch this page with IE and FireFox (or browser with different name, major version ), and we will see that there is different cache version (See the date) for different browser.

3. VaryByControl:  The attribute is representing the ID property values of ASP.NET server controls, which is used to vary output cache.



Note: Run ASP.NET web application and launch this page. Display result will not changed till 10s even if we try to change option in drop down

4. VaryByParam:  The string is used to vary the output cache. By default, these strings correspond to a query string.

Run ASP.NET web application and launch this page, and we can request it using QueryString "id" with different value.
For example:
~/ Default.aspx?id=1
~/ Default.aspx?id=2




Location:  The attribute is one of the OutputCacheLocation enumeration values (such as Web server, proxy server or browser) which indicate where page is cached. The default is Any.

                                                                             ... To be continued

About Author:
Amit Sulankhe is a consultant in Systems Plus Pvt. Ltd. Within Systems Plus, he actively contributes to the areas of Technology and Information Security. He can be contacted at amit.salunkhe@spluspl.com

1 comment: