Skip navigation links

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

E13403-06


oracle.javatools.util
Class Maps.TimedLruCacheStrategy<K,V>

java.lang.Object
  extended by oracle.javatools.util.Maps.CacheStrategy<K,V>
      extended by oracle.javatools.util.Maps.BoundedLruCacheStrategy<K,V>
          extended by oracle.javatools.util.Maps.TimedLruCacheStrategy<K,V>

All Implemented Interfaces:
java.io.Serializable
Enclosing class:
Maps

public static class Maps.TimedLruCacheStrategy<K,V>
extends Maps.BoundedLruCacheStrategy<K,V>

A timed, bounded size LRU cache strategy.

A synchronous timed cache evicts expired entries whenever standard map methods are invoked by clients. Locking issues are assumed to be handled by clients.

An asynchronous timed cache additionally evicts expired entries periodically from a background thread owned by the strategy. On that thread, the strategy must handle the locking, so the strategy requires that a lock object be passed to the constructor. To protect its invocation of periodicTaskExecuted(oracle.javatools.util.Maps.CacheMap<K, V>), if the lock object implements Lock, then the strategy uses Lock.lock() and Lock.unlock(); otherwise the strategy uses the object monitor lock (it synchronizes on the object).

See Also:
Maps.CacheMap, Maps.CacheStrategy, Serialized Form

Field Summary

 

Fields inherited from class oracle.javatools.util.Maps.CacheStrategy
CANONICAL, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, HARD, NONCANONICAL, NOT_CANONICAL, SOFT, STRONG, WEAK

 

Constructor Summary
Maps.TimedLruCacheStrategy(int time)
          Constructs a timed, synchronous, unbounded, canonical cache strategy of strongly-referenced values.
Maps.TimedLruCacheStrategy(int time, int bound)
          Constructs a timed, synchronous, bounded LRU (least recently used), canonical cache strategy of strongly-referenced values.
Maps.TimedLruCacheStrategy(int time, int bound, int initialCapacity, float loadFactor, Maps.CacheMap.Canonicity canonicity, Maps.CacheMap.Strength strength)
          Constructs a timed, synchronous, bounded LRU (least recently used) cache strategy.
Maps.TimedLruCacheStrategy(int time, int period, java.lang.Object lock)
          Constructs a timed, asynchronous, unbounded, canonical cache strategy of strongly-referenced values.
Maps.TimedLruCacheStrategy(int time, int period, java.lang.Object lock, int bound)
          Constructs a timed, asynchronous, bounded LRU (least recently used), canonical cache strategy of strongly-referenced values.
Maps.TimedLruCacheStrategy(int time, int period, java.lang.Object lock, int bound, int initialCapacity, float loadFactor, Maps.CacheMap.Canonicity canonicity, Maps.CacheMap.Strength strength)
          Constructs a timed, bounded LRU (least recently used) cache strategy.

 

Method Summary
protected  Maps.LinkedEntry<K,V> createDefaultEntry(int hashCode, K key, V value, Maps.LinkedEntry<K,V> next)
           
protected  Maps.LinkedEntry<K,V> createEvictedEntry(int hashCode, K key, V value, Maps.LinkedEntry<K,V> next, java.lang.ref.ReferenceQueue<V> queue)
           
protected  Maps.LinkedEntry<K,V> createSoftEntry(int hashCode, K key, V value, Maps.LinkedEntry<K,V> next, java.lang.ref.ReferenceQueue<V> queue)
           
protected  Maps.LinkedEntry<K,V> createWeakEntry(int hashCode, K key, V value, Maps.LinkedEntry<K,V> next, java.lang.ref.ReferenceQueue<V> queue)
           
protected  void entryAccessed(Maps.CacheMap<K,V> map, Maps.LinkedEntry<K,V> entry)
          Invoked when the value of an existing entry is accessed by Maps.AbstractHashMap.get(java.lang.Object).
protected  void entryAdded(Maps.CacheMap<K,V> map, Maps.LinkedEntry<K,V> entry)
          Invoked when a new entry is added to this map, when entries are added by Maps.AbstractHashMap.put(K, V).
protected  void entryChanged(Maps.CacheMap<K,V> map, Maps.LinkedEntry<K,V> oldEntry, V oldValue, Maps.LinkedEntry<K,V> newEntry)
          Invoked when the value of an existing entry is changed or when entries are changed by Maps.AbstractHashMap.put(K, V).
protected  void entryEvicted(Maps.CacheMap<K,V> map, Maps.LinkedEntry<K,V> entry)
          Invoked when an existing entry is evicted by Maps.AbstractLinkedHashMap.evictEntry(E).
protected  void entryPurged(Maps.CacheMap<K,V> map, Maps.LinkedEntry<K,V> entry)
          Invoked when an existing entry is purged after its value has been garbage collected.
protected  void entryRemoved(Maps.CacheMap<K,V> map, Maps.LinkedEntry<K,V> entry)
          Invoked when an existing entry is removed by a remove method of this map, of a view collection of this map, or of an iterator of a view collection of this map

The Maps.CacheMap implementation never invokes Maps.CacheStrategy.entryRemoved(oracle.javatools.util.Maps.CacheMap<K, V>, oracle.javatools.util.Maps.LinkedEntry<K, V>) when entries are removed by the Maps.CacheMap.clear() method of this map, or of a view collection of this map.

protected  void evictExpiredEntries(Maps.CacheMap<K,V> map)
          Evict expired entries from the Maps.CacheMap}.
protected  void mapConstructed(Maps.CacheMap<K,V> map)
          Invoked when the map has constructed.
protected  void periodicTaskExecuted(Maps.CacheMap<K,V> map)
          Invoked when the periodic timer expires.

 

Methods inherited from class oracle.javatools.util.Maps.CacheStrategy
createEntry, getCanonicity, getDefaultStrength, getInitialCapacity, getLoadFactor, mapChanged

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Constructor Detail

Maps.TimedLruCacheStrategy

public Maps.TimedLruCacheStrategy(int time)
Constructs a timed, synchronous, unbounded, canonical cache strategy of strongly-referenced values.
Parameters:
time - The maximum age (ms) of entries allowed in the cache.

Maps.TimedLruCacheStrategy

public Maps.TimedLruCacheStrategy(int time,
                                  int period,
                                  java.lang.Object lock)
Constructs a timed, asynchronous, unbounded, canonical cache strategy of strongly-referenced values.
Parameters:
time - The maximum age (ms) of entries allowed in the cache.
period - The period (ms) of asynchronous eviction.
lock - The lock to use for asynchronous eviction.

Maps.TimedLruCacheStrategy

public Maps.TimedLruCacheStrategy(int time,
                                  int bound)
Constructs a timed, synchronous, bounded LRU (least recently used), canonical cache strategy of strongly-referenced values.
Parameters:
time - The maximum age (ms) of entries allowed in the cache.
bound - The maximum number of entries allowed in the cache.

Maps.TimedLruCacheStrategy

public Maps.TimedLruCacheStrategy(int time,
                                  int period,
                                  java.lang.Object lock,
                                  int bound)
Constructs a timed, asynchronous, bounded LRU (least recently used), canonical cache strategy of strongly-referenced values.
Parameters:
time - The maximum age (ms) of entries allowed in the cache.
period - The period (ms) of asynchronous eviction.
lock - The lock to use for asynchronous eviction.
bound - The maximum number of entries allowed in the cache.

Maps.TimedLruCacheStrategy

public Maps.TimedLruCacheStrategy(int time,
                                  int bound,
                                  int initialCapacity,
                                  float loadFactor,
                                  Maps.CacheMap.Canonicity canonicity,
                                  Maps.CacheMap.Strength strength)
Constructs a timed, synchronous, bounded LRU (least recently used) cache strategy.
Parameters:
time - The maximum age (ms) of entries allowed in the cache.
bound - The maximum number of entries allowed in the cache.
initialCapacity - The initial capacity (see Maps.CacheStrategy.DEFAULT_INITIAL_CAPACITY).
loadFactor - The load factor (see Maps.CacheStrategy.DEFAULT_LOAD_FACTOR).
canonicity - Canonicity of this cache.
strength - The strength of value references.

Maps.TimedLruCacheStrategy

public Maps.TimedLruCacheStrategy(int time,
                                  int period,
                                  java.lang.Object lock,
                                  int bound,
                                  int initialCapacity,
                                  float loadFactor,
                                  Maps.CacheMap.Canonicity canonicity,
                                  Maps.CacheMap.Strength strength)
Constructs a timed, bounded LRU (least recently used) cache strategy.
Parameters:
time - The maximum age (ms) of entries allowed in the cache.
period - The period (ms) of asynchronous eviction.
lock - The lock to use for asynchronous eviction.
bound - The maximum number of entries allowed in the cache.
initialCapacity - The initial capacity (see Maps.CacheStrategy.DEFAULT_INITIAL_CAPACITY).
loadFactor - The load factor (see Maps.CacheStrategy.DEFAULT_LOAD_FACTOR).
canonicity - Canonicity of this cache.
strength - The strength of value references.

Method Detail

mapConstructed

protected void mapConstructed(Maps.CacheMap<K,V> map)
Invoked when the map has constructed.

The Maps.CacheStrategy implementation does nothing.

The default Maps.TimedLruCacheStrategy implementation adds the newly constructed map to the list of maps to be serviced, and ensures that a periodic task is scheduled to service the map.

The periodic task, when invoked, evicts expired entries using evictExpiredEntries(oracle.javatools.util.Maps.CacheMap<K, V>). Once all the maps to be serviced are garbage collected, the task cancels itself.

Overrides:
mapConstructed in class Maps.CacheStrategy<K,V>

createDefaultEntry

protected Maps.LinkedEntry<K,V> createDefaultEntry(int hashCode,
                                                   K key,
                                                   V value,
                                                   Maps.LinkedEntry<K,V> next)
Overrides:
createDefaultEntry in class Maps.CacheStrategy<K,V>

createSoftEntry

protected Maps.LinkedEntry<K,V> createSoftEntry(int hashCode,
                                                K key,
                                                V value,
                                                Maps.LinkedEntry<K,V> next,
                                                java.lang.ref.ReferenceQueue<V> queue)
Overrides:
createSoftEntry in class Maps.CacheStrategy<K,V>

createWeakEntry

protected Maps.LinkedEntry<K,V> createWeakEntry(int hashCode,
                                                K key,
                                                V value,
                                                Maps.LinkedEntry<K,V> next,
                                                java.lang.ref.ReferenceQueue<V> queue)
Overrides:
createWeakEntry in class Maps.CacheStrategy<K,V>

createEvictedEntry

protected Maps.LinkedEntry<K,V> createEvictedEntry(int hashCode,
                                                   K key,
                                                   V value,
                                                   Maps.LinkedEntry<K,V> next,
                                                   java.lang.ref.ReferenceQueue<V> queue)
Overrides:
createEvictedEntry in class Maps.CacheStrategy<K,V>

evictExpiredEntries

protected void evictExpiredEntries(Maps.CacheMap<K,V> map)
Evict expired entries from the Maps.CacheMap}.

The Maps.TimedLruCacheStrategy implementation removes LRU entries with a time older than maximumAge before the current time.


periodicTaskExecuted

protected void periodicTaskExecuted(Maps.CacheMap<K,V> map)
Invoked when the periodic timer expires.

The Maps.TimedLruCacheStrategy implementation purges the map and invokes evictExpiredEntries(oracle.javatools.util.Maps.CacheMap<K, V>).


entryAdded

protected void entryAdded(Maps.CacheMap<K,V> map,
                          Maps.LinkedEntry<K,V> entry)
Invoked when a new entry is added to this map, when entries are added by Maps.AbstractHashMap.put(K, V).

The Maps.CacheStrategy implementation does nothing.

The Maps.BoundedLruCacheStrategy implementation evicts the eldest entry in the map if the size of the map after the add exceeds the maximum size.

The Maps.TimedLruCacheStrategy implementation delegates to evictExpiredEntries(oracle.javatools.util.Maps.CacheMap<K, V>).

Overrides:
entryAdded in class Maps.BoundedLruCacheStrategy<K,V>

entryChanged

protected void entryChanged(Maps.CacheMap<K,V> map,
                            Maps.LinkedEntry<K,V> oldEntry,
                            V oldValue,
                            Maps.LinkedEntry<K,V> newEntry)
Invoked when the value of an existing entry is changed or when entries are changed by Maps.AbstractHashMap.put(K, V).

If the entry to change was mutable, its value is changed with Map.Entry#setValue and oldEntry and newEntry are the same object. If the entry to change was not mutable, a new entry must be created and oldEntry and newEntry are different objects.

When a client directly invokes the Map.Entry#setValue method of any of the Map.Entry implementations provided in this class, this method is not invoked (while this could be addressed, it would require each entry instance to hold a reference to its map).

The Maps.CacheStrategy implementation does nothing.

The Maps.TimedLruCacheStrategy implementation delegates to evictExpiredEntries(oracle.javatools.util.Maps.CacheMap<K, V>).

Overrides:
entryChanged in class Maps.CacheStrategy<K,V>
oldEntry - The existing entry that changed.
oldValue - The old value of the entry.
newEntry - The new entry, which may be the same as the old.

entryAccessed

protected void entryAccessed(Maps.CacheMap<K,V> map,
                             Maps.LinkedEntry<K,V> entry)
Invoked when the value of an existing entry is accessed by Maps.AbstractHashMap.get(java.lang.Object). Access to an entry by iterating a view collection of this map does not cause this method to be invoked.

The Maps.CacheStrategy implementation does nothing.

The Maps.TimedLruCacheStrategy implementation delegates to evictExpiredEntries(oracle.javatools.util.Maps.CacheMap<K, V>).

Overrides:
entryAccessed in class Maps.CacheStrategy<K,V>

entryRemoved

protected void entryRemoved(Maps.CacheMap<K,V> map,
                            Maps.LinkedEntry<K,V> entry)
Invoked when an existing entry is removed by a remove method of this map, of a view collection of this map, or of an iterator of a view collection of this map

The Maps.CacheMap implementation never invokes Maps.CacheStrategy.entryRemoved(oracle.javatools.util.Maps.CacheMap<K, V>, oracle.javatools.util.Maps.LinkedEntry<K, V>) when entries are removed by the Maps.CacheMap.clear() method of this map, or of a view collection of this map.

The Maps.CacheStrategy implementation does nothing.

The Maps.TimedLruCacheStrategy implementation delegates to evictExpiredEntries(oracle.javatools.util.Maps.CacheMap<K, V>).

Overrides:
entryRemoved in class Maps.CacheStrategy<K,V>

entryPurged

protected void entryPurged(Maps.CacheMap<K,V> map,
                           Maps.LinkedEntry<K,V> entry)
Invoked when an existing entry is purged after its value has been garbage collected.

The Maps.CacheMap implementation only ever invokes Maps.CacheStrategy.entryPurged(oracle.javatools.util.Maps.CacheMap<K, V>, oracle.javatools.util.Maps.LinkedEntry<K, V>) for entries which extend SoftReference or WeakReference and which register themselves with the ReferenceQueue returned by Maps.AbstractHashMap.getQueue(). Maps provides four such classes: Maps.SoftEntry, Maps.WeakEntry, Maps.SoftLinkedEntry, and Maps.WeakLinkedEntry.

The Maps.CacheStrategy implementation does nothing.

The Maps.TimedLruCacheStrategy implementation delegates to evictExpiredEntries(oracle.javatools.util.Maps.CacheMap<K, V>).

Overrides:
entryPurged in class Maps.CacheStrategy<K,V>

entryEvicted

protected void entryEvicted(Maps.CacheMap<K,V> map,
                            Maps.LinkedEntry<K,V> entry)
Invoked when an existing entry is evicted by Maps.AbstractLinkedHashMap.evictEntry(E).

If this map is canonical, eviction means the entry was converted to a weak reference and Maps.CacheStrategy.mapChanged(oracle.javatools.util.Maps.CacheMap<K, V>) was not invoked. If the map is not canonical, eviction means the entry was removed and Maps.CacheStrategy.mapChanged(oracle.javatools.util.Maps.CacheMap<K, V>) was invoked.

The Maps.CacheStrategy implementation does nothing.

The Maps.TimedLruCacheStrategy implementation does nothing.

Overrides:
entryEvicted in class Maps.CacheStrategy<K,V>

Skip navigation links

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

E13403-06


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