Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.1.0)

E17493-02

oracle.ide.util
Class TimedCache<K,V>

java.lang.Object
  extended by oracle.ide.util.TimedCache<K,V>

Deprecated. This class can lead to memory usage issues. This class uses expiration time as the sole means of cache expiration. This means that cached objects remain pinned in memory for a fixed amount of time whether they are needed or not. It also makes no provision for removing cached objects during periods of high memory usage, which could lead to OutOfMemoryError. This class also makes use of a timer thread which stays running for the duration of the JVM, which is not appropriate for use at application runtime. The map implementations provided by the Maps are typically a better solution, especially the memory sensitive implementations based on weak or soft references.

public final class TimedCache<K,V>
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
          Deprecated. The default expiration (in minutes) for an instance of a timer cache that was created without a specified expiration.
static int MAXIMUM_EXPIRATION
          Deprecated. The maximum expiration (in minutes) that can be set on any object or as the default.
static int NEVER_EXPIRES
          Deprecated. The constant to specify in place of an expiration time to indicate that the given object should never expire.
 
Constructor Summary
TimedCache()
          Deprecated. Constructs a new, empty TimedCache instance with default expiration on objects added to the cache.
TimedCache(int defaultExpiration)
          Deprecated. 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()
          Deprecated. Clears the contents of this cache.
 V get(K key)
          Deprecated. Retrieves a previously cached object from the cache.
static
<K,V> TimedCache<K,V>
newInstance()
          Deprecated. Static factory method to create a new TimedCache instance with the default expiration time, capacity, and load factor.
static
<K,V> TimedCache<K,V>
newInstance(int defaultExpiration)
          Deprecated. Static factory method to create a new TimedCache instance with the deafult capacity and load factor.
static
<K,V> TimedCache<K,V>
newInstance(int defaultExpiration, int initialCapacity, float loadFactor)
          Deprecated. Static factory method to create a new TimedCache instance.
 void put(K key, V value)
          Deprecated. Stores an object into the cache.
 void put(K key, V value, int expiration)
          Deprecated. Stores an object into the cache.
 V remove(K key)
          Deprecated. Removes the mapping for this key from the cache if present.
 void setDefaultExpiration(int defaultExpiration)
          Deprecated. Changes the default expiration used by the cache for objects stored in the cache without an explicit expiration.
 void setExpiration(K key, int expiration)
          Deprecated. 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
Deprecated. 
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
Deprecated. 
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 Timer uses millisecond quantities.

See Also:
Constant Field Values

NEVER_EXPIRES

public static final int NEVER_EXPIRES
Deprecated. 
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()
Deprecated. 
Constructs a new, empty TimedCache instance with default expiration on objects added to the cache.


TimedCache

public TimedCache(int defaultExpiration)
Deprecated. 
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

newInstance

public static <K,V> TimedCache<K,V> newInstance()
Deprecated. 
Static factory method to create a new TimedCache instance with the default expiration time, capacity, and load factor.

Returns:
the new instance

newInstance

public static <K,V> TimedCache<K,V> newInstance(int defaultExpiration)
Deprecated. 
Static factory method to create a new TimedCache instance with the deafult capacity and load factor.

Parameters:
defaultExpiration - the expiration (in minutes) to set by default, or DEFAULT_EXPIRATION for the default, or NEVER_EXPIRES
Returns:
the new instance

newInstance

public static <K,V> TimedCache<K,V> newInstance(int defaultExpiration,
                                                int initialCapacity,
                                                float loadFactor)
Deprecated. 
Static factory method to create a new TimedCache instance.

Parameters:
defaultExpiration - the expiration (in minutes) to set by default, or DEFAULT_EXPIRATION for the default, or NEVER_EXPIRES
initialCapacity - the initial capacity of the cache
loadFactor - the load factor of the cache
Returns:
the new instance

get

public V get(K key)
Deprecated. 
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(K key,
                V value)
Deprecated. 
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(K key,
                V value,
                int expiration)
Deprecated. 
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 V remove(K key)
Deprecated. 
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 defaultExpiration)
Deprecated. 
Changes the default expiration used by the cache for objects stored in the cache without an explicit expiration.

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

setExpiration

public void setExpiration(K key,
                          int expiration)
Deprecated. 
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()
Deprecated. 
Clears the contents of this cache. All previously cached objects will be removed.


Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.1.0)

E17493-02

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