com.caucho.util
Class TimedCache<K,V>

java.lang.Object
  extended by com.caucho.util.TimedCache<K,V>

public class TimedCache<K,V>
extends java.lang.Object

A timed LRU cache. Items remain valid until they expire. TimedCache can simplify database caching.


 TimedCache storyCache = new TimedCache(30, 60000);

 public Story getCurrentStory(String id)
 {
   Story story = (Story) storyCache.get(id);

   if (story == null) {
     story = DB.queryStoryDatabase(id);
     storyCache.put(id, story);
   }

   return story;
 }
 


Constructor Summary
TimedCache(int capacity, long expireInterval)
          Creates a new timed LRU cache.
 
Method Summary
 V get(K key)
          Gets an item from the cache, returning null if expired.
 V put(K key, V value)
          Put a new item in the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimedCache

public TimedCache(int capacity,
                  long expireInterval)
Creates a new timed LRU cache.

Parameters:
capacity - the maximum size of the LRU cache
expireInterval - the time an entry remains valid
Method Detail

put

public V put(K key,
             V value)
Put a new item in the cache.


get

public V get(K key)
Gets an item from the cache, returning null if expired.