Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.caucho.util
Class TimedCache

    java.lang.Object
      |
      +--com.caucho.util.LruCache
            |
            +--com.caucho.util.TimedCache

public class TimedCache
extends LruCache

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
`java.lang.Object` | `get(java.lang.Object key)` Gets an item from the cache, returning null if expired.
`java.lang.Object` | `put(java.lang.Object key, java.lang.Object value)` Put a new item in the cache.

Methods inherited from class com.caucho.util.LruCache
`clear, keys, keys, remove, removeTail, size, values, values`

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 java.lang.Object put(java.lang.Object key,
                                java.lang.Object value)

  Put a new item in the cache.
  Overrides:
    `put` in class `LruCache`
  Following copied from class: `com.caucho.util.LruCache`
  Parameters:
    `key` - key to store data
    `value` - value to be stored
  Returns:
    old value stored under the key

### get

    public java.lang.Object get(java.lang.Object key)

  Gets an item from the cache, returning null if expired.
  Overrides:
    `get` in class `LruCache`
  Following copied from class: `com.caucho.util.LruCache`
  Parameters:
    `key` - key to lookup the item
  Returns:
    the matching object in the cache

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD