ASP.NET
  Home arrow ASP.NET arrow Page 3 - How Caching Means More Ca-ching, Part 2
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 2
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 41
    2004-04-27

    Table of Contents:
  • How Caching Means More Ca-ching, Part 2
  • Methods
  • You're Too Old, Please Leave
  • Learn to Set Priorities!

  • 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 2 - You're Too Old, Please Leave


    (Page 3 of 4 )

    So how exactly can we set a maximum age requirement for the cached data? Well I hate you tell you that you have more options, but it's true. I know, first you have the option of which caching method to choose. Then if you've chosen data caching, you've got three more option of how to implement it. Then, if you've decided on .insert or .add, you have the control options. You've finally decided to use a time expiration, and are very tired. This is why I'm sorry to present more options to you, but I'm afraid I have to.

    Firstly, the most straightforward option is just to set an absolute expiration time. Here's how you could do that:


    strVal "I'm learning so much!"
    cache
    .insert("item"strValnothingdatetime.now.addminutes(10), timespan.zero) 'there should be no carriage return here

    Ok, some explanation is needed. That 'nothing' that you see is the dependency option, which will be discussed next. That needs to be there. You may quickly decipher that we're telling the object to expire in 10 minutes, but maybe you're wondering what the last option is, the timespan.zero. That us the sliding expiration time, which I will explain next. Just remember that both must be represented by some value, if you are to use either option. Also remember that only one can be used at a time.

    The second option, which was turned off in the last example by the use of timespan.zero, is called the sliding expiration policy. This will 'slide' the time to get rid of the object until a specified time after the last request for that object. We set this option in the following way:


    strVal "Caching is so much fun!"
    cache
    .insert("item"strValnothingdatetime.maxvalue
    timespan
    .fromseconds(60)) 'there should be no carriage return here

    Nothing to cryptic in that code, just note that the datetime.maxvalue disables the absolute expiration, because as I'm confident that you remembered, only one can be used at a time. So now let's go back to first option in the chain, the dependency option.

    Do You Have Any Dependents?

    I find this to be a very cool option. We can tell the application to leave the object in cache, depending entirely on the variability of another object. That other object is monitored for any changes, and as soon as a change is detected, the cached object expires! This could be a file, another cached object, or even multiple objects! Here's an example in code:


    strVal "I may or may not have understood these directions..."
    cache
    .insert("item"strVal, New CacheDependency(Server.MapPath("depend.xml")))

    I'm assuming that you're already making plans of how to use this, and I don't blame you -- it is very powerful. However, in Whidbey (ASP.NET version 2) you will have the option of setting the dependency to be upon an actual database, now THAT's powerful! But I guess until we have a public release, this will have to suffice! Ok, enough coveting what we do not have, let's continue learning what's now within our grasp.

    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-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT