uPortal 2.4.1
API Documentation

org.jasig.portal.concurrency.caching
Class LRUCache

java.lang.Object
  extended byjava.util.AbstractMap
      extended byjava.util.HashMap
          extended byorg.jasig.portal.concurrency.caching.LRUCache
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class LRUCache
extends java.util.HashMap

A rewrite of SmartCache that uses a moderate LRU algorithm: entries are purged from the cache via periodic sweeps rather than in response to specific cache additions. Note that sweeps have to be kicked off externally, e.g.,

int MAX_CACHE_SIZE = 1000;
int MAX_UNUSED_TIME_MILLIS = 30*60*1000;
LRUCache cache = new LRUCache(MAX_CACHE_SIZE, MAX_UNUSED_TIME_MILLIS);
// ... put stuff in ...
cache.sweepCache()
// ... put more stuff in ...

At the end of the sweep, the cache will have no more (and possibly less) than maxSize entries, though the sweep may have to reduce maxUnusedTimeMillis in order to get there.

Version:
$Revision: 1.5.6.1 $
Author:
Ken Weiner, Dan Ellentuck
See Also:
SmartCache, Serialized Form

Constructor Summary
LRUCache()
           
LRUCache(int size)
           
LRUCache(int size, int maxUnusedAge)
           
 
Method Summary
 void clear()
          Synchronizes removal of ALL entries from the cache.
 java.lang.Object get(java.lang.Object key)
          Get the object from the cache and reset the timestamp.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Add a new value to the cache.
 java.lang.Object remove(java.lang.Object key)
          Synchronizes removal of an entry from the cache.
 void sweepCache()
          Sweep the cache until it gets back under maxSize.
 
Methods inherited from class java.util.HashMap
clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

LRUCache

public LRUCache()

LRUCache

public LRUCache(int size)

LRUCache

public LRUCache(int size,
                int maxUnusedAge)
Parameters:
size - int
maxUnusedAge - int
Method Detail

clear

public void clear()
Synchronizes removal of ALL entries from the cache.


get

public java.lang.Object get(java.lang.Object key)
Get the object from the cache and reset the timestamp.

Parameters:
key - the key, typically a String
Returns:
the value to which the key is mapped in this cache; null if the key is not mapped to any value in this cache.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Add a new value to the cache.

Parameters:
key - the key, typically a String
value - the value
Returns:
the previous value of the specified key in this hashtable, or null if it did not have one.

remove

public java.lang.Object remove(java.lang.Object key)
Synchronizes removal of an entry from the cache.

Parameters:
key - the key, typically a String
Returns:
the previous value of the specified key in this hashtable, or null if it did not have one.

sweepCache

public void sweepCache()
Sweep the cache until it gets back under maxSize.


uPortal 2.4.1
API Documentation