ASP.NET
  Home arrow ASP.NET arrow Page 2 - How Caching Means More Ca-ching, Part 1
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

How Caching Means More Ca-ching, Part 1
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 29
    2004-04-21

    Table of Contents:
  • How Caching Means More Ca-ching, Part 1
  • Output Caching
  • Call The HttpCachePolicy!
  • Fragment Caching

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    How Caching Means More Ca-ching, Part 1 - Output Caching


    (Page 2 of 4 )

    Output caching is probably the least exciting of the three. More or less, we're going to employ this on full pages that wouldn't change more than every few hours. Really though, when we're talking about a dynamic (most often database-driven) application, most of the pages are less pages than they are 'panels', providing little to much functionality, and changing constantly. Perhaps what would qualify more for output caching is something like a Frequently Asked Questions or Help section. This is something that many people will be requesting, but in most cases will not be exceedingly dynamic. This is an area where you could benefit from output caching.

    To make use of output caching, we can do it quickly and simply by throwing in the @OutputCache directive at the top of our .aspx page. It might look a little like this:


    <%@ OutputCache Duration="600" VaryByParam="None" %>

    This will cache the entire page for 10 minutes. That means that everything, including a <%= now() %> block, will remain the same and be served from memory in 10 minute increments. We change this amount of time through the Duration attribute, which takes seconds as its values.

    What you're probably wondering about is that goofy looking VaryByParam bit. Don't think that just because it doesn't look like it belongs that you can leave it out. Try it, you'll get a complaint in the form of a runtime error. This is absolutely required. The purpose is to allow a small degree of dynamics to an otherwise static page. We can leave it as the default none, or put it to use caching different versions of the page depending on parameters received either through GET or POST methods.

    To explain: suppose we want to cache a different help page for beginner and advanced users. We could set to cache to vary by the parameter of the 'groupID' like this:


    <%@ OutputCache Duration="600" VaryByParam="goupIP" %>

    and when we request the page -- let's say 'help.aspx' –- like this:


    /help.aspx?groupID=newbie

    we would get a different cached paged than if we requested the following:


    /help.aspx?groupID=oldshoe

    This is pretty cool, as it allows us to be not entirely inflexible. There are two other attributes of the @OutputCache directive, VaryByHeader and VaryByCustom. VaryByHeader is somewhat obvious allowing us to vary the output cache by certain HTTP headers. This would be helpful if we were for instance, caching dynamic output based on languages or user-agents. The third and final attribute, VaryByCustom, can vary the output cache depending on custom settings such as the browser version of the client. This is most likely the least likely to be used. Poor little guy.

    More ASP.NET Articles
    More By Justin Cook


     

    ASP.NET ARTICLES

    - How Caching Means More Ca-ching, Part 2
    - How Caching Means More Ca-ching, Part 1
    - Reading a Delimited File Using ASP.Net and V...
    - What is .Net and Where is ASP.NET?
    - An Object Driven Interface with .Net
    - Create Your Own Guestbook In ASP.NET
    - HTTP File Download Without User Interaction ...
    - Dynamically Using Methods in ASP.NET
    - Changing the Page Size Interactively in a Da...
    - XML Serialization in ASP.NET
    - Using Objects in ASP.NET: Part 1/2
    - IE Web Controls in VB.NET
    - Class Frameworks in VB .NET
    - Cryptographic Objects in C#: Part 1
    - Sample Chapter: Pure ASP.Net







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek