org.apache.taglibs.cache
Class LRUCache

java.lang.Object
  extended byorg.apache.taglibs.cache.LRUCache

public class LRUCache
extends java.lang.Object

A Map implementing a cache using an LRU cache-replacement algorithm. Following the general Map contract, this class requires explicit, outside synchronization in the event of concurrent access.

Unlike similar LRU-based caches that implement Map (e.g., from Jakarta Commons), this class has a hard size limit (in characters), not a limit on the total number of elements.

This class works like a Map for the methods it implements, but for simplicity, it is not a full Map. I'd rather implement the full Map contract than just pay lip service to its methods.

Author:
Shawn Bayern

Constructor Summary
LRUCache(int size, int lifetime)
          Constructs an LRUCache that holds no more than size characters.
 
Method Summary
 void clear()
           
 java.lang.String get(java.lang.Object key)
           
 int getCurrentSize()
           
 java.util.Set keySet()
           
static void main(java.lang.String[] args)
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 java.lang.Object remove(java.lang.Object key)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LRUCache

public LRUCache(int size,
                int lifetime)
Constructs an LRUCache that holds no more than size characters. Each entry expires after expiration seconds, or never expires if expiration less than or equal to 0.

Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

clear

public void clear()

get

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

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)

remove

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

keySet

public java.util.Set keySet()

getCurrentSize

public int getCurrentSize()


Copyright ? 2000-2004 The Apache Software Foundation. All Rights Reserved.