Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
6 Months Free & No Setup Fees ASP.NET Hosting!
Search :       Advanced Search »
Home » ASP.NET 2.0/3.5 » New features of Caching

New features of Caching

This article provides the knowledge of CACHING in ASP.NET 2.0. In this article you will get the new features of caching.

Author Rank :
Page Views : 7054
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Nevron Gauge for SharePoint
Become a Sponsor
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

Overview of caching

Caching is an important concept in computing. When applied to ASP.NET, it can greatly enhance the performance of your Web applications. Caching is used to speed up the performance of the application. We can store these into cache memory. The retrieval of these pages will be fast.

ASP.NET 2.0 frameworks support the following types of caching.

 

  • Page output caching
  • Partial page caching
  • Data source caching
  • Data caching

Page output Caching

Output caching caches the output of a page (or portions of it) so that a page's content need not be generated every time it is loaded.

Consider the following page where a user logs in to a site and reads the latest news. The page will display the user's name and retrieve the latest news since he last logged in.

                    

Figure 1: Displaying the latest news.

In a typical ASP.NET page, every time the user views the page, the Web server will have to dynamically generate the content of the page and perform the relevant database queries (which are a very expensive task to do).

Considering the fact that the page does not change for a certain period of time, It is always a good idea to cache whatever is non-static so that the page can be loaded quickly.

Specifying the cache location

You can use the location attribute of the <%@ output cache %> directive to specify where a page is cached. This attribute accepts the following values:

1.      Any

2.      Client

3.      Downstream

4.      None

5.      Server

6.      Server and client

Any: A page is cached on the browser, proxy server, and web server(the default value).

 

Client: The page is cached only on the browser.

 

Downstream: The page is cached on the browser and any proxy server, but not the web server.

 

None:  The page will not cache on browser/proxy server/web server.

 

Server: The page is cached on the web server but not on the browser or any proxy server.

 

Server and client: The page is cached on the browser and web server, but not any proxy server.

 

By default, when you use page output caching, a page is cache in three locations:

 

  • The web server
  • Proxy server
  • The browser  

These are situations in which you might need to modify this default behavior.

For example: If you caching private information then you don't want to cache the information on the web server or any proxy server.

 

Note:  When windows authentication is enabled in the web configuration file (the default). The cache control header is automatically set to the value private, and setting of the location attribute is ignored.

 

Default caching is for five minute.

 

To judge caching date time class when the page goes in cache then there is date and time and when we retrieve the page then no change in date and time because no processing on the server.

 

Best option for caching is on client.

 

State management is used to access the data at one page to another.

 

Manipulating the page output cache programmatically: There are three attributes use to manipulate the page output caching in asp.net2.0

 

  1. Vary by param
  2. Vary by header
  3. vary by custom 

Vary by Param: In vary by param the caching perform on the basis of the parameter list which is supplied at run time. The Vary by param attribute specifies how the caching should be performed, based on the query string supplied to the page.

 

Vary by header: In very by header the caching perform on the basis of language.(the default language of system is US English).this can be done by satali0te assemblies and culture assemblies.

 

Vary by custom: In vary by custom the caching is performing on the basis of browser.

 

Data caching: For data caching we create cache object to store into the cache.Cache variable are like application variable are declare on fly and can be access into the page of the root directory. We can direct use the cache object with the key or we can use the insert or add method of the cache object.

 

New Cache Features:

Cache Profiles

Cache profiles allow you to create cache settings in an application's Web.config file and then reference those settings on individual pages. This allows you to apply cache settings to many pages at once.

Custom Cache Dependencies

In ASP.NET 2.0 you can create your own custom cache dependency based on application-specific conditions. To create a custom cache dependency, you create a class that inherits from Cache Dependency and in your custom class implement your own dependency methods.

SqlCacheDependency

ASP.NET 2.0 introduces the SqlCacheDependency class, which allows you to configure an item in the cache to have a dependency on a table or row in a Microsoft SQL Server database. ASP.NET 2.0 allows you to set a dependency on a table in SQL Server 7.0, SQL Server 2000, and SQL Server 2005. When using SQL Server 2005, you can also set a dependency on a specific record.

Post-Cache Substitution

ASP.NET 2.0 now supports post-cache substitution, which allows you to configure a section in a page as non-cacheable.

Caching Enhancements:

  • Control  Caching
  • Cache configuration Enhancement.

In ASP.NET 2.0, you can configure user control cache settings at run time with the CachePolicy object. The CachePolicy object allows you to work with user control caching the same way that you can work programmatically with page output caching.

ASP.NET 2.0 introduces new cache configuration settings that you can specify in an application's Web.config file. These settings allow more control over the cache, such as how much memory is used and cache scavenging behavior.

Time-Based Caching:

Another technique for caching is based on time. For example, the cache can expire on a certain date, or it will only be available for a certain period of time. There are two ways in which you can use time-based caching:

  1. Absolute Expiration. The cache is set to expire on a particular date and time.
  2. Sliding Expiration. The cache is set to expire after a certain period of inactivity.

Conclusion:

 

Caching of Web pages is an effective way of increasing performance while minimizing the use of precious server resources. Choosing the appropriate level for caching data is important for balancing caching versus memory usage. One of the most effective strategies to good Web application performance is to cache data only when necessary. 

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Purushottam Rathore

I am working as a Software Developer and has 4 years of experience on Microsoft Technology and having a Master Degree in Computer Application. I really like to work in the .NET platform. and working with ASP.NET 2.0/3.5, Web Services, WPF, WCF, Silverlight, AJAX, JavaScript, JQuery, Ado.net, MsAccess, SQL Server 2005/2008.

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Team Foundation Server Hosting
Become a Sponsor
 Comments
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.