Extension SDK 10.1.2

oracle.ide.util
Class TimedCache

java.lang.Object
  extended byoracle.ide.util.TimedCache

public class TimedCache
extends java.lang.Object

The TimedCache is an implementation of a cache that is based around an expiration timer. The underlying data store of the cache is a HashMap, so objects are stored and retrieved from the cache using a (preferably immutable) key. Note that this implementation does not permit null keys. Any use of a null key will result in a NullPointerException being thrown.

When storing an object in the cache, an expiration delay should be specified which indicates how long that object will be stored in the cache, without being accessed, before it is removed from the cache. The default expiration time, if none is specified, is 10 minutes per object. As long as the object is accessed, via the get() method, the object will remain in the cache. Expiration times can be specified on a per-object basis. The value NEVER_EXPIRES, as the name implies, can also be specified to prevent expiration of the object.


Field Summary
static int DEFAULT_EXPIRATION
          The default expiration (in minutes) for an instance of a timer cache that was created without a specified expiration.
static int MAXIMUM_EXPIRATION
          The maximum expiration (in minutes) that can be set on any object or as the default.
static int NEVER_EXPIRES
          The constant to specify in place of an expiration time to indicate that the given object should never expire.
 
Constructor Summary
TimedCache()
          Constructs a new, empty TimedCache instance with default expiration on objects added to the cache.
TimedCache(int defaultExpiration)
          Constructs a new, empty TimedCache instance with the specified default expiration on objects added to the cache without an expiration time.
 
Method Summary
 void clear()
          Clears the contents of this cache.
 java.lang.Object get(java.lang.Object key)
          Retrieves a previously cached object from the cache.
 void put(java.lang.Object key, java.lang.Object value)
          Stores an object into the cache.
 void put(java.lang.Object key, java.lang.Object value, int expiration)
          Stores an object into the cache.
 java.lang.Object remove(java.lang.Object key)
          Removes the mapping for this key from the cache if present
 void setDefaultExpiration(int expiration)
          Changes the default expiration used by the cache for objects stored in the cache without an explicit expiration.
 void setExpiration(java.lang.Object key, int expiration)
          Changes the expiration on a previously cached object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_EXPIRATION

public static final int DEFAULT_EXPIRATION
The default expiration (in minutes) for an instance of a timer cache that was created without a specified expiration. The default expiration is currently 10 minutes.

See Also:
Constant Field Values

MAXIMUM_EXPIRATION

public static final int MAXIMUM_EXPIRATION
The maximum expiration (in minutes) that can be set on any object or as the default. This is arbitrary and is put in place to prevent number overflows since Swing Timer's use millisecond quantities.

See Also:
Constant Field Values

NEVER_EXPIRES

public static final int NEVER_EXPIRES
The constant to specify in place of an expiration time to indicate that the given object should never expire. This can also be specified as the default expiration when constructing a new TimedCache instance.

See Also:
Constant Field Values
Constructor Detail

TimedCache

public TimedCache()
Constructs a new, empty TimedCache instance with default expiration on objects added to the cache.


TimedCache

public TimedCache(int defaultExpiration)
Constructs a new, empty TimedCache instance with the specified default expiration on objects added to the cache without an expiration time.

Parameters:
defaultExpiration - the expiration (in minutes) to set by default, or DEFAULT_EXPIRATION for the default, or NEVER_EXPIRES
Method Detail

get

public java.lang.Object get(java.lang.Object key)
Retrieves a previously cached object from the cache. The key specified is used to locate the cached object. If the object is not found, null is returned. This has the side effect of restarting the expiration timer on this cached object. Note that "null" keys are not allowed.

Parameters:
key - the search key for locating the cached object
Returns:
the previously cached object, or null if not found

put

public void put(java.lang.Object key,
                java.lang.Object value)
Stores an object into the cache. The key specified is used to determine the location for storing the object into the cache, and the default expiration used for determining when the object should expire and be removed from the cache. This has the side effect of starting the timer when called. Note that "null" keys are not allowed.

Parameters:
key - the search key for determing the storage location
value - the object to store

put

public void put(java.lang.Object key,
                java.lang.Object value,
                int expiration)
Stores an object into the cache. The key specified is used to determine the location for storing the object into the cache, and the specified expiration (in minutes) used for determining when the object should expire and be removed from the cache. This has the side effect of starting the timer when called. Note that "null" keys are not allowed.

Parameters:
key - the search key for determing the storage location
value - the object to store
expiration - the new expiration time in minutes to set, or DEFAULT_EXPIRATION for the default, or NEVER_EXPIRES

remove

public java.lang.Object remove(java.lang.Object key)
Removes the mapping for this key from the cache if present

Parameters:
key - the key for looking up the cache object to remove
Returns:
the value previously associated with the specified key, or null if no there was no mapping for the key

setDefaultExpiration

public void setDefaultExpiration(int expiration)
Changes the default expiration used by the cache for objects stored in the cache without an explicit expiration.


setExpiration

public void setExpiration(java.lang.Object key,
                          int expiration)
Changes the expiration on a previously cached object. The key specified is used to locate the cached object, and the specified expiration (in minutes) set as the new expiration. This has the side effect of restarting the timer for this cached object. Note that "null" keys are not allowed.

Parameters:
key - the search key for locating the cached object
expiration - the new expiration time in minutes to set, or DEFAULT_EXPIRATION for the default, or NEVER_EXPIRES

clear

public void clear()
Clears the contents of this cache. All previously cached objects will be removed.


Extension SDK

 

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