|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap
com.tangosol.util.SafeHashMap
com.tangosol.net.cache.OldCache
LocalCache
public class OldCache
A generic cache manager.
The implementation is thread safe and uses a combination of Most Recently Used (MRU) and Most Frequently Used (MFU) caching strategies.
The cache is size-limited, which means that once it reaches its maximum size ("high-water mark") it prunes itself (to its "low-water mark"). The cache high- and low-water-marks are measured in terms of "units", and each cached item by default uses one unit. All of the cache constructors, except for the default constructor, require the maximum number of units to be passed in. To change the number of units that each cache entry uses, either set the Units property of the cache entry, or extend the Cache implementation so that the inner Entry class calculates its own unit size. To determine the current, high-water and low-water sizes of the cache, use the cache object's Units, HighUnits and LowUnits properties. The HighUnits and LowUnits properties can be changed, even after the cache is in use. To specify the LowUnits value as a percentage when constructing the cache, use the extended constructor taking the percentage-prune-level.
Each cached entry expires after one hour by default. To alter this behavior, use a constructor that takes the expiry-millis; for example, an expiry-millis value of 10000 will expire entries after 10 seconds. The ExpiryDelay property can also be set once the cache is in use, but it will not affect the expiry of previously cached items.
The cache can optionally be flushed on a periodic basis by setting the FlushDelay property or scheduling a specific flush time by setting the FlushTime property.
Cache hit statistics can be obtained from the CacheHits, CacheMisses, HitProbability, KeyHitProbability and CompositeHitProbability read-only properties. The statistics can be reset by invoking resetHitStatistics. The statistics are automatically reset when the cache is cleared (the clear method).
The OldCache implements the ObservableMap interface, meaning it provides event notifications to any interested listener for each insert, update and delete, including those that occur when the cache is pruned or entries are automatically expired.
This implementation is designed to support extension through inheritence. When overriding the inner Entry class, the OldCache.instantiateEntry factory method must be overridden to instantiate the correct Entry sub-class. To override the one-unit-per-entry default behavior, extend the inner Entry class and override the calculateUnits method.
Nested Class Summary | |
---|---|
class |
OldCache.Entry
Deprecated. A holder for a cached value. |
protected class |
OldCache.EntrySet
Deprecated. A set of entries backed by this map. |
static interface |
OldCache.EvictionPolicy
Deprecated. An eviction policy is an object that the cache provides with access information, and when requested, the eviction policy selects and evicts entries from the cache. |
protected class |
OldCache.KeySet
Deprecated. A set of entries backed by this map. |
static interface |
OldCache.UnitCalculator
Deprecated. A unit calculator is an object that can calculate the cost of caching an object. |
protected class |
OldCache.ValuesCollection
Deprecated. A collection of values backed by this map. |
Field Summary | |
---|---|
static int |
DEFAULT_EXPIRE
Deprecated. By default, the cache entries expire after one hour. |
static int |
DEFAULT_FLUSH
Deprecated. By default, expired cache entries are flushed on a minute interval. |
static double |
DEFAULT_PRUNE
Deprecated. By default, when the cache prunes, it reduces its entries by 25%, meaning it retains 75% (.75) of its entries. |
static int |
DEFAULT_UNITS
Deprecated. By default, the cache size (in units). |
static int |
EVICTION_POLICY_EXTERNAL
Deprecated. The cache can prune using an external eviction policy. |
static int |
EVICTION_POLICY_HYBRID
Deprecated. By default, the cache prunes based on a hybrid LRU+LFU algorithm. |
static int |
EVICTION_POLICY_LFU
Deprecated. The cache can prune based on a pure Least Frequently Used (LFU) algorithm. |
static int |
EVICTION_POLICY_LRU
Deprecated. The cache can prune based on a pure Least Recently Used (LRU) algorithm. |
protected OldCache.UnitCalculator |
m_calculator
Deprecated. The external unit calculator. |
protected int |
m_cCurUnits
Deprecated. The current number of units in the cache. |
protected int |
m_cExpiryDelay
Deprecated. The number of milliseconds that a value will live in the cache. |
protected int |
m_cFlushDelay
Deprecated. The interval between full cache flushes, in milliseconds. |
protected int |
m_cMaxUnits
Deprecated. The number of units to allow the cache to grow to before pruning. |
protected int |
m_cPruneUnits
Deprecated. The number of units to prune the cache down to. |
protected MapListenerSupport |
m_listenerSupport
Deprecated. The MapListenerSupport object. |
protected long |
m_lNextFlush
Deprecated. The time (ie System.currentTimeMillis) at which the next full cache flush should occur. |
protected int |
m_nCalculatorType
Deprecated. The type of unit calculator employed by the cache; one of the UNIT_CALCULATOR_* enumerated values. |
protected int |
m_nEvictionType
Deprecated. The type of eviction policy employed by the cache; one of the EVICTION_POLICY_* enumerated values. |
protected OldCache.EvictionPolicy |
m_policy
Deprecated. The eviction policy; for eviction type EVICTION_POLICY_EXTERNAL. |
protected SimpleCacheStatistics |
m_stats
Deprecated. The CacheStatistics object maintained by this cache. |
static int |
UNIT_CALCULATOR_BINARY
Deprecated. Specifies a unit calculator that assigns an object a weight equal to the number of bytes of memory required to cache the object. |
static int |
UNIT_CALCULATOR_EXTERNAL
Deprecated. Specifies a external (custom) unit calculator implementation. |
static int |
UNIT_CALCULATOR_FIXED
Deprecated. Specifies the default unit calculator that weighs all entries equally as 1. |
Fields inherited from class com.tangosol.util.SafeHashMap |
---|
BIGGEST_MODULO, DEFAULT_GROWTHRATE, DEFAULT_INITIALSIZE, DEFAULT_LOADFACTOR, m_aeBucket, m_cCapacity, m_cEntries, m_colValues, m_flGrowthRate, m_flLoadFactor, m_oIterActive, m_setEntries, m_setKeys, PRIME_MODULO, RESIZING |
Constructor Summary | |
---|---|
OldCache()
Deprecated. Construct the cache manager. |
|
OldCache(int cUnits)
Deprecated. Construct the cache manager. |
|
OldCache(int cUnits,
int cExpiryMillis)
Deprecated. Construct the cache manager. |
|
OldCache(int cUnits,
int cExpiryMillis,
double dflPruneLevel)
Deprecated. Construct the cache manager. |
Method Summary | |
---|---|
void |
addMapListener(MapListener listener)
Deprecated. Add a standard map listener that will receive all events (inserts, updates, deletes) that occur against the map, with the key, old-value and new-value included. |
void |
addMapListener(MapListener listener,
Filter filter,
boolean fLite)
Deprecated. Add a map listener that receives events based on a filter evaluation. |
void |
addMapListener(MapListener listener,
Object oKey,
boolean fLite)
Deprecated. Add a map listener for a specific key. |
protected void |
adjustUnits(int cDelta)
Deprecated. Adjust current size. |
protected void |
checkFlush()
Deprecated. Check if the cache is timed out, and clear if it is. |
protected void |
checkSize()
Deprecated. Check if the cache is too big, and if it is prune it by discarding the lowest priority cache entries. |
void |
clear()
Deprecated. Remove everything from the cache. |
protected void |
configureEviction(int nType,
OldCache.EvictionPolicy policy)
Deprecated. Configure the eviction type and policy. |
protected void |
configureUnitCalculator(int nType,
OldCache.UnitCalculator calculator)
Deprecated. Configure the unit calculator type and implementation. |
boolean |
containsKey(Object key)
Deprecated. Returns true if the cache contains the specified key. |
protected void |
deferFlush()
Deprecated. Defer the next flush by scheduling it for infinity and beyond. |
protected void |
dispatchEvent(MapEvent evt)
Deprecated. Dispatch the passed event. |
void |
evict()
Deprecated. Evict all entries from the cache that are no longer valid, and potentially prune the cache size if the cache is size-limited and its size is above the caching low water mark. |
void |
evict(Object oKey)
Deprecated. Evict a specified key from the cache, as if it had expired from the cache. |
void |
evictAll(Collection colKeys)
Deprecated. Evict the specified keys from the cache, as if they had each expired from the cache. |
Object |
get(Object oKey)
Deprecated. If the specified item is in the cache, return it. |
long |
getCacheHits()
Deprecated. Determine the rough number of cache hits since the cache statistics were last reset. |
long |
getCacheMisses()
Deprecated. Determine the rough number of cache misses since the cache statistics were last reset. |
CacheStatistics |
getCacheStatistics()
Deprecated. Returns the CacheStatistics for this cache. |
SafeHashMap.Entry |
getEntry(Object oKey)
Deprecated. Locate an Entry in the hash map based on its key. |
protected SafeHashMap.Entry |
getEntryInternal(Object oKey)
Deprecated. Locate an Entry in the hash map based on its key. |
OldCache.EvictionPolicy |
getEvictionPolicy()
Deprecated. Determine the current external eviction policy, if any. |
int |
getEvictionType()
Deprecated. Determine the current eviction type. |
int |
getExpiryDelay()
Deprecated. Determine the "time to live" for each individual cache entry. |
int |
getFlushDelay()
Deprecated. Determine the delay between cache flushes. |
long |
getFlushTime()
Deprecated. Determine the date/time at which the next cache flush is scheduled. |
int |
getHighUnits()
Deprecated. Determine the limit of the cache size in units. |
double |
getHitProbability()
Deprecated. Determine the rough probability (0 <= p <= 1) that any particular get(java.lang.Object) invocation will be satisfied by an existing entry in
the cache, based on the statistics collected since the last reset
of the cache statistics. |
int |
getLowUnits()
Deprecated. Determine the point to which the cache will shrink when it prunes. |
protected MapListenerSupport |
getMapListenerSupport()
Deprecated. Accessor for the MapListenerSupport for sub-classes. |
OldCache.UnitCalculator |
getUnitCalculator()
Deprecated. Determine the current external unit calculator, if any. |
int |
getUnitCalculatorType()
Deprecated. Determine the current unit calculator type. |
int |
getUnits()
Deprecated. Determine the number of units that the cache currently stores. |
protected boolean |
hasListeners()
Deprecated. Determine if the OverflowMap has any listeners at all. |
protected SafeHashMap.Entry |
instantiateEntry()
Deprecated. Factory method. |
protected SafeHashMap.EntrySet |
instantiateEntrySet()
Deprecated. Factory pattern. |
protected SafeHashMap.KeySet |
instantiateKeySet()
Deprecated. Factory pattern. |
protected MapEvent |
instantiateMapEvent(int nId,
Object oKey,
Object oValueOld,
Object oValueNew)
Deprecated. Factory pattern: instantiate a new MapEvent corresponding to the specified parameters. |
protected SafeHashMap.ValuesCollection |
instantiateValuesCollection()
Deprecated. Factory pattern. |
protected void |
prune()
Deprecated. Prune the cache by discarding the lowest priority cache entries. |
Object |
put(Object oKey,
Object oValue)
Deprecated. Store a value in the cache. |
Object |
put(Object oKey,
Object oValue,
long cMillis)
Deprecated. Store a value in the cache that will be automatically evicted according to the specified expiration value. |
Object |
remove(Object oKey)
Deprecated. Remove an entry from the cache. |
protected void |
removeExpired(OldCache.Entry entry,
boolean fRemoveInternal)
Deprecated. Remove an entry because it has expired. |
void |
removeMapListener(MapListener listener)
Deprecated. Remove a standard map listener that previously signed up for all events. |
void |
removeMapListener(MapListener listener,
Filter filter)
Deprecated. Remove a map listener that previously signed up for events based on a filter evaluation. |
void |
removeMapListener(MapListener listener,
Object oKey)
Deprecated. Remove a map listener that previously signed up for events about a specific key. |
void |
resetHitStatistics()
Deprecated. Reset the cache statistics. |
protected void |
scheduleFlush()
Deprecated. Schedule the next flush. |
void |
setEvictionPolicy(OldCache.EvictionPolicy policy)
Deprecated. Set the external eviction policy, and change the eviction type to EVICTION_POLICY_EXTERNAL. |
void |
setEvictionType(int nType)
Deprecated. Specify the eviction type for the cache. |
void |
setExpiryDelay(int cMillis)
Deprecated. Specify the "time to live" for cache entries. |
void |
setFlushDelay(int cMillis)
Deprecated. Specify the delay between cache flushes. |
void |
setFlushTime(long lMillis)
Deprecated. Specify the date/time at which the next cache flush is to occur. |
void |
setHighUnits(int cMax)
Deprecated. Update the maximum size of the cache in units. |
void |
setLowUnits(int cUnits)
Deprecated. Specify the point to which the cache will shrink when it prunes. |
void |
setUnitCalculator(OldCache.UnitCalculator calculator)
Deprecated. Set the external unit calculator, and change the unit calculator type to UNIT_CALCULATOR_EXTERNAL. |
void |
setUnitCalculatorType(int nType)
Deprecated. Specify the unit calculator type for the cache. |
int |
size()
Deprecated. Returns the number of key-value mappings in this map. |
String |
toString()
Deprecated. For debugging purposes, format the contents of the cache as a String. |
Methods inherited from class com.tangosol.util.SafeHashMap |
---|
clone, cloneEntryList, entrySet, getBucketIndex, getStableBucketArray, grow, isActiveIterator, isEmpty, iteratorActivated, iteratorDeactivated, keySet, removeEntryInternal, values |
Methods inherited from class java.util.AbstractMap |
---|
containsValue, equals, hashCode, putAll |
Methods inherited from interface java.util.Map |
---|
containsValue, entrySet, equals, hashCode, isEmpty, keySet, putAll, values |
Field Detail |
---|
public static final int DEFAULT_UNITS
public static final int DEFAULT_EXPIRE
public static final int DEFAULT_FLUSH
public static final double DEFAULT_PRUNE
public static final int EVICTION_POLICY_HYBRID
public static final int EVICTION_POLICY_LRU
public static final int EVICTION_POLICY_LFU
public static final int EVICTION_POLICY_EXTERNAL
public static final int UNIT_CALCULATOR_FIXED
public static final int UNIT_CALCULATOR_BINARY
BinaryMemoryCalculator
,
Constant Field Valuespublic static final int UNIT_CALCULATOR_EXTERNAL
protected int m_cCurUnits
protected int m_cMaxUnits
protected int m_cPruneUnits
protected int m_cExpiryDelay
protected int m_cFlushDelay
protected volatile long m_lNextFlush
protected SimpleCacheStatistics m_stats
protected MapListenerSupport m_listenerSupport
protected int m_nEvictionType
protected OldCache.EvictionPolicy m_policy
protected int m_nCalculatorType
protected OldCache.UnitCalculator m_calculator
Constructor Detail |
---|
public OldCache()
public OldCache(int cUnits)
cUnits
- the number of units that the cache manager will cache
before pruning the cachepublic OldCache(int cUnits, int cExpiryMillis)
cUnits
- the number of units that the cache manager will
cache before pruning the cachecExpiryMillis
- the number of milliseconds that each cache entry
lives before being automatically expiredpublic OldCache(int cUnits, int cExpiryMillis, double dflPruneLevel)
cUnits
- the number of units that the cache manager will
cache before pruning the cachecExpiryMillis
- the number of milliseconds that each cache entry
lives before being automatically expireddflPruneLevel
- the percentage of the total number of units that
will remain after the cache manager prunes the
cache (i.e. this is the "low water mark" value);
this value is in the range 0.0 to 1.0Method Detail |
---|
public int size()
size
in interface Map
size
in class SafeHashMap
public boolean containsKey(Object key)
containsKey
in interface Map
containsKey
in class SafeHashMap
key
- key whose presence in this map is to be tested
public Object get(Object oKey)
get
in interface Map
get
in class SafeHashMap
oKey
- the key to the desired cached item
public SafeHashMap.Entry getEntry(Object oKey)
getEntry
in class SafeHashMap
oKey
- the key object to search for
public Object put(Object oKey, Object oValue)
put
in interface Map
put
in class SafeHashMap
oKey
- the key with which to associate the cache valueoValue
- the value to cache
public Object put(Object oKey, Object oValue, long cMillis)
oKey
- the key with which to associate the cache valueoValue
- the value to cachecMillis
- the number of milliseconds until the entry will expire;
pass zero to use the cache's default ExpiryDelay settings;
pass -1 to indicate that the entry should never expire
public Object remove(Object oKey)
remove
in interface Map
remove
in class SafeHashMap
oKey
- the key of a cached value
public void clear()
clear
in interface Map
clear
in class SafeHashMap
public void addMapListener(MapListener listener)
addMapListener(listener, (Filter) null, false);
addMapListener
in interface ObservableMap
listener
- the MapEvent
listener to addpublic void removeMapListener(MapListener listener)
removeMapListener(listener, (Filter) null);
removeMapListener
in interface ObservableMap
listener
- the listener to removepublic void addMapListener(MapListener listener, Object oKey, boolean fLite)
The listeners will receive MapEvent objects, but if fLite is passed as true, they might not contain the OldValue and NewValue properties.
To unregister the MapListener, use the
ObservableMap.removeMapListener(MapListener, Object)
method.
addMapListener
in interface ObservableMap
listener
- the MapEvent
listener to addoKey
- the key that identifies the entry for which to raise
eventsfLite
- true to indicate that the MapEvent
objects do
not have to include the OldValue and NewValue
property values in order to allow optimizationspublic void removeMapListener(MapListener listener, Object oKey)
removeMapListener
in interface ObservableMap
listener
- the listener to removeoKey
- the key that identifies the entry for which to raise
eventspublic void addMapListener(MapListener listener, Filter filter, boolean fLite)
The listeners will receive MapEvent objects, but if fLite is passed as true, they might not contain the OldValue and NewValue properties.
To unregister the MapListener, use the
ObservableMap.removeMapListener(MapListener, Filter)
method.
addMapListener
in interface ObservableMap
listener
- the MapEvent
listener to addfilter
- a filter that will be passed MapEvent objects to select
from; a MapEvent will be delivered to the listener only
if the filter evaluates to true for that MapEvent (see
MapEventFilter
);
null is equivalent to a filter that alway returns truefLite
- true to indicate that the MapEvent
objects do
not have to include the OldValue and NewValue
property values in order to allow optimizationspublic void removeMapListener(MapListener listener, Filter filter)
removeMapListener
in interface ObservableMap
listener
- the listener to removefilter
- the filter that was passed into the corresponding
addMapListener() callpublic void evict(Object oKey)
oKey
- the key to evict from the cachepublic void evictAll(Collection colKeys)
The result of this method is defined to be semantically the same as the following implementation: for (Iterator iter = colKeys.iterator(); iter.hasNext(); ) { Object oKey = iter.next(); evict(oKey); }
colKeys
- a collection of keys to evict from the cachepublic void evict()
public CacheStatistics getCacheStatistics()
protected SafeHashMap.EntrySet instantiateEntrySet()
instantiateEntrySet
in class SafeHashMap
protected SafeHashMap.KeySet instantiateKeySet()
instantiateKeySet
in class SafeHashMap
protected SafeHashMap.ValuesCollection instantiateValuesCollection()
instantiateValuesCollection
in class SafeHashMap
public String toString()
toString
in class AbstractMap
public int getUnits()
public int getHighUnits()
public void setHighUnits(int cMax)
cMax
- the new maximum size of the cache, in unitspublic int getLowUnits()
public void setLowUnits(int cUnits)
cUnits
- the number of units that the cache prunes topublic int getEvictionType()
public void setEvictionType(int nType)
nType
- one of the EVICTION_POLICY_* enumerated valuespublic OldCache.EvictionPolicy getEvictionPolicy()
public void setEvictionPolicy(OldCache.EvictionPolicy policy)
policy
- an external eviction policy, or null to use the default
policypublic int getUnitCalculatorType()
public void setUnitCalculatorType(int nType)
nType
- one of the UNIT_CALCULATOR_* enumerated valuespublic OldCache.UnitCalculator getUnitCalculator()
public void setUnitCalculator(OldCache.UnitCalculator calculator)
calculator
- an external unit calculator, or null to use the default
unit calculatorpublic int getExpiryDelay()
public void setExpiryDelay(int cMillis)
cMillis
- the number of milliseconds that cache entries will
live, or zero to disable automatic expirypublic int getFlushDelay()
public void setFlushDelay(int cMillis)
cMillis
- the number of milliseconds between cache flushes, or
zero to never flushpublic long getFlushTime()
public void setFlushTime(long lMillis)
lMillis
- the date/time value, in milliseconds, when the cache
should next automatically flushpublic long getCacheHits()
get(java.lang.Object)
calls that have been served by
existing cache entriespublic long getCacheMisses()
get(java.lang.Object)
calls that failed to find an
existing cache entry because the requested key was not in the
cachepublic double getHitProbability()
get(java.lang.Object)
invocation will be satisfied by an existing entry in
the cache, based on the statistics collected since the last reset
of the cache statistics.
public void resetHitStatistics()
protected void configureEviction(int nType, OldCache.EvictionPolicy policy)
nType
- one of the EVICTION_POLICY_* enumerated valuespolicy
- an external eviction policy, or nullprotected void configureUnitCalculator(int nType, OldCache.UnitCalculator calculator)
nType
- one of the UNIT_CALCULATOR_* enumerated valuescalculator
- an external unit calculator, or nullprotected SafeHashMap.Entry getEntryInternal(Object oKey)
getEntry(java.lang.Object)
method, this method does not flush the cache
(if necessary) or update cache statistics.
getEntryInternal
in class SafeHashMap
oKey
- the key object to search for
protected void removeExpired(OldCache.Entry entry, boolean fRemoveInternal)
entry
- the expired cache entryfRemoveInternal
- true if the cache entry still needs to be
removed from the cacheprotected void adjustUnits(int cDelta)
protected void checkSize()
protected void prune()
protected void checkFlush()
protected void deferFlush()
protected void scheduleFlush()
protected MapEvent instantiateMapEvent(int nId, Object oKey, Object oValueOld, Object oValueNew)
protected MapListenerSupport getMapListenerSupport()
protected boolean hasListeners()
protected void dispatchEvent(MapEvent evt)
evt
- a CacheEvent objectprotected SafeHashMap.Entry instantiateEntry()
instantiateEntry
in class SafeHashMap
|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |