Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)

E13403-03

oracle.jdeveloper.java.util
Class TimedLRUCache

java.lang.Object
  extended by oracle.jdeveloper.java.util.TimedLRUCache

public class TimedLRUCache
extends java.lang.Object

The TimedLRUCache is a timed and LRU cache that discards least-recently-used excess or expired cached entries. The cache checks for these excess or expired cache entries only at periodic intervals so as not to be overly aggressive about pruning the cache.

Clients have to specify the size of the cache - when the cache exceeds this specified size, least-recently-used cached entries will be discarded automatically.

Clients can also specify an optional time-to-live expiration for entries. Cached entries that have not been accessed within that timeframe will also be discarded automatically. The minimum expiration time that can be specified is defined by MINIMUM_EXPIRATION which is currently 60 seconds. Clients can also specify that entries should never expire by specifying NO_EXPIRATION.

This cache does not support null keys, or null values.


Field Summary
static int MINIMUM_EXPIRATION
          The smallest expiration time (milliseconds) this cache will used.
static int NO_EXPIRATION
          Constant indicating that the cache does not have an expiration policy based on time.
 
Constructor Summary
TimedLRUCache(int maxSize)
          Constructs a new TimedLRUCache with the given max size.
TimedLRUCache(int maxSize, int timeToLiveMillis)
          Construct a new TimedLRUCache with the given max size and time-to-live for the entries.
 
Method Summary
protected  void checkForExpiration()
          Checks for expiration in the cache, whether it is least-recently used or timer based.
protected  boolean containsKey(java.lang.Object key)
          Checks whether the cache contains the given key.
 java.lang.Object get(java.lang.Object key)
          Fetches an object from the cache for the given key.
 void put(java.lang.Object key, java.lang.Object value)
          Stores an object into the cache under the given key.
 java.lang.Object remove(java.lang.Object key)
          Removes an object from the cache using the given lookup key.
protected  int size()
          Fetches the size of the cache currently.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_EXPIRATION

public static final int NO_EXPIRATION
Constant indicating that the cache does not have an expiration policy based on time.

See Also:
Constant Field Values

MINIMUM_EXPIRATION

public static final int MINIMUM_EXPIRATION
The smallest expiration time (milliseconds) this cache will used.

See Also:
Constant Field Values
Constructor Detail

TimedLRUCache

public TimedLRUCache(int maxSize)
Constructs a new TimedLRUCache with the given max size.

Parameters:
maxSize - the maximum size of the cache

TimedLRUCache

public TimedLRUCache(int maxSize,
                     int timeToLiveMillis)
Construct a new TimedLRUCache with the given max size and time-to-live for the entries.

Parameters:
maxSize - the maximum size of the cache
timeToLiveMillis - the time-to-live for the entries (milliseconds)
Method Detail

get

public java.lang.Object get(java.lang.Object key)
Fetches an object from the cache for the given key. This will update the last access time of the object.

Parameters:
key - the key of the entry to lookup
Returns:
the entry corresponding to the given key, or null if it is not found

put

public void put(java.lang.Object key,
                java.lang.Object value)
Stores an object into the cache under the given key. This will update the last access time of the object.

Parameters:
key - the key to store the value under
value - the value to store with the key

remove

public java.lang.Object remove(java.lang.Object key)
Removes an object from the cache using the given lookup key.

Parameters:
key - the key to use for looking up the object
Returns:
the value that was removed, or null if the key was not found in the cache

containsKey

protected boolean containsKey(java.lang.Object key)
Checks whether the cache contains the given key. This is used for testing purposes only.


size

protected int size()
Fetches the size of the cache currently. This is used for testing purposes only.


checkForExpiration

protected void checkForExpiration()
Checks for expiration in the cache, whether it is least-recently used or timer based.


Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)

E13403-03

Copyright © 1997, 2009, Oracle. All rights reserved.