Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Time Sensitive Caches
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post will appear after it is approved by moderators
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Paul Marrington  
View profile  
 More options Sep 25 2005, 11:29 pm
From: Paul Marrington <pa...@askowl.com.au>
Date: Sun, 25 Sep 2005 20:29:31 -0700 (PDT)
Local: Sun, Sep 25 2005 11:29 pm
Subject: [Adept Open Source Library] Time Sensitive Caches
Nothing is forever. If you have a program that is short-lived compared to the mean time between change of the data being cached, then a LRU cache will be more than adequate. If the program is an application server and could be left running for days, weeks or even months - then there's a good chance that the data being cached will need to be changed. Enter the time sensitive cache. A time sensitive cache can be created with a special constructor or built from a LRU cache with the ageingCache method. In both cases you provide the number of minutes cached items are useful for (as either a property or a number) and a flag set to true to fix the expiry time.
// Once 50 elements are cached the least recently accessed will be discarded.
Cache cache = new Cache( 50);
// Or if the items are 6 hours old
cache.ageingCache( 6 * 60, true);

 

Every 30 seconds the cache daemon checks all caches for expired entries and removes them. If you attempt to retrieve a cached item after it expires it will be cleared then. It's the responsibility of the calling code to reload an expired item; as this is exactly the same as opening it the first time, no additional code should be necessary.
byte[] buffer = cache.get( fileName);
if (buffer == null)
  buffer = readFile( fileName);

 

If you need for an entry to be reloaded early, call expire(). If you want to clear the entire cache, just create a new instance and let the old clean itself up. Since time sensitive caches rarely hold Closeable there should be few concerns about locked entries.

Time sensitive caches are typically used to store data that's needed regularly and is more expensive to retrieve from the original source. Two common examples include files and reference data in a database.

Next week will talk about how to use Cache for time-limiting caches. This is the same technology but for a completely different application.



--
Posted by Paul Marrington to Adept Open Source Library at 9/26/2005 01:26:00 PM

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google