Class LocalCache
- All Implemented Interfaces:
CacheMap,ConfigurableCacheMap,ObservableMap,Serializable,Cloneable,Map
- Since:
- Coherence 2.2
- Author:
- cp 2003.05.30
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassA holder for a cached value.protected classA set of entries backed by this map.static classThe InternalEvictionPolicy represents a pluggable eviction policy for the non-pluggable built-in (internal) eviction policies supported by this cache implementation.protected classAn internal MapListener that listens to this cache and reports changes to the CacheStore.static classThe InternalUnitCalculator represents a pluggable UnitCalculator for the non-pluggable built-in (internal) UnitCalculator implementation provided by this cache implementation.protected classA class that masks certain changes so that they are not reported back to the CacheStore.protected classA set of entries backed by this map.protected classA collection of values backed by this map.Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> Nested classes/interfaces inherited from interface com.tangosol.net.cache.ConfigurableCacheMap
ConfigurableCacheMap.EvictionApprover, ConfigurableCacheMap.EvictionPolicy, ConfigurableCacheMap.UnitCalculator -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intBy default, the cache entries never expire.static final intDeprecated.as of Coherence 3.5protected final LocalCache.KeyMaskThe default key mask that ignores nothing.static final doubleBy default, when the cache prunes, it reduces its entries to this percentage.static final intBy default, the cache size (in units) is infinite.static final intThe cache can prune using an external eviction policy.static final intBy default, the cache prunes based on a hybrid LRU+LFU algorithm.static final intThe cache can prune based on a pure Least Frequently Used (LFU) algorithm.static final intThe cache can prune based on a pure Least Recently Used (LRU) algorithm.static final ConfigurableCacheMap.UnitCalculatorThe UnitCalculator object that measures the bytes used by entries.static final ConfigurableCacheMap.UnitCalculatorThe UnitCalculator object that counts each entry as one unit.static final ConfigurableCacheMap.EvictionPolicyThe EvictionPolicy object for the Hybrid eviction algorithm.static final ConfigurableCacheMap.EvictionPolicyThe EvictionPolicy object for the Least Frequently Used (LFU) eviction algorithm.static final ConfigurableCacheMap.EvictionPolicyThe EvictionPolicy object for the Least Recently Used (LRU) eviction algorithm.protected ConfigurableCacheMap.EvictionApproverThe EvictionApprover.protected LongArrayArray of set of keys, indexed by the time of expiry.protected ConfigurableCacheMap.UnitCalculatorThe external unit calculator.protected intFor a prune cycle, this value is the average number of touches that an entry should have.protected longThe current number of units in the cache.protected intThe number of milliseconds that a value will live in the cache.protected longThe number of units to allow the cache to grow to before pruning.protected longThe number of units to prune the cache down to.protected doubleThe 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.0.protected booleanSpecifies whether or not this cache will incrementally evict.protected booleanSpecifies whether or not this cache is used in the environment, where theBase.getSafeTimeMillis()is used very frequently and as a result, theBase.getLastSafeTimeMillis()could be used without sacrificing the clock precision.protected ListIteratorFor deferred eviction, iterator of entries to evict.protected MapListenerSupportThe MapListenerSupport object.protected longThe last time that a prune was run.protected longThe time before which a expired-entries flush will not be performed.protected intThe type of unit calculator employed by the cache; one of the UNIT_CALCULATOR_* enumerated values.protected intThe type of eviction policy employed by the cache; one of the EVICTION_POLICY_* enumerated values.protected intThe unit factor.protected ConfigurableCacheMap.EvictionPolicyThe eviction policy; for eviction type EVICTION_POLICY_EXTERNAL.protected SimpleCacheStatisticsThe CacheStatistics object maintained by this cache.static final intSpecifies a unit calculator that assigns an object a weight equal to the number of bytes of memory required to cache the object.static final intSpecifies a external (custom) unit calculator implementation.static final intSpecifies 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, RESIZINGFields inherited from interface com.tangosol.net.cache.CacheMap
EXPIRY_DEFAULT, EXPIRY_NEVER -
Constructor Summary
ConstructorsConstructorDescriptionConstruct the cache manager.LocalCache(int cUnits) Construct the cache manager.LocalCache(int cUnits, int cExpiryMillis) Construct the cache manager.LocalCache(int cUnits, int cExpiryMillis, double dflPruneLevel) Construct the cache manager.LocalCache(int cUnits, int cExpiryMillis, CacheLoader loader) Construct the cache manager. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMapListener(MapListener listener) 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.voidaddMapListener(MapListener listener, Filter filter, boolean fLite) Add a map listener that receives events based on a filter evaluation.voidaddMapListener(MapListener listener, Object oKey, boolean fLite) Add a map listener for a specific key.protected voidadjustUnits(int cDelta) Adjust current size.protected voidDeprecated.as of Coherence 3.5, useevict()voidclear()Removes all mappings from this map.protected voidconfigureEviction(int nType, ConfigurableCacheMap.EvictionPolicy policy) Configure the eviction type and policy.protected voidconfigureUnitCalculator(int nType, ConfigurableCacheMap.UnitCalculator calculator) Configure the unit calculator type and implementation.booleancontainsKey(Object key) Returns true if this map contains a mapping for the specified key.protected voiddispatchEvent(MapEvent evt) Dispatch the passed event.voidevict()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.voidEvict a specified key from the cache, as if it had expired from the cache.voidevictAll(Collection colKeys) Evict the specified keys from the cache, as if they had each expired from the cache.Returns the value to which this map maps the specified key.getAll(Collection colKeys) Get all the specified keys, if they are in the cache.getCacheEntry(Object oKey) Locate a cache Entry in the cache based on its key.longDetermine the rough number of cache hits since the cache statistics were last reset.Determine the loader used by this LocalCache, if any.longDetermine the rough number of cache misses since the cache statistics were last reset.Returns the CacheStatistics for this cache.protected CacheStoreDetermine the store used by this LocalCache, if any.longReturn the currentsafe timeorlast safe timedepending on the optimization flag.Locate an Entry in the hash map based on its key.protected SafeHashMap.EntrygetEntryInternal(Object oKey) Locate an Entry in the hash map based on its key.Obtain the registered EvictionApprover.Obtain the current EvictionPolicy used by the cache.intDetermine the current eviction type.intDetermine the default "time to live" for each individual cache entry.longDeprecated.as of Coherence 3.5intDetermine the limit of the cache size in units.doubleDetermine the rough probability (0 <= p <= 1) that any particularget(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.protected LocalCache.KeyMaskThreadLocal: Get the current key mask for the current thread.intDetermine the point to which the cache will shrink when it prunes.protected MapListenerSupportAccessor for the MapListenerSupport for sub-classes.longDetermine the next expiry time for the cache entries.Obtain the current UnitCalculator used by the cache.intDetermine the current unit calculator type.intDetermine the factor by which the Units, LowUnits and HighUnits properties are adjusted.intgetUnits()Determine the number of units that the cache currently stores.protected booleanDetermine if the LocalCache has any listeners at all.protected SafeHashMap.EntryFactory method.protected SafeHashMap.EntrySetFactory pattern.protected MapListenerFactory pattern: Instantiate an internal MapListener to listen to this cache and report changes to the CacheStore.protected SafeHashMap.KeySetFactory pattern.protected MapEventinstantiateMapEvent(int nId, Object oKey, Object oValueOld, Object oValueNew) Factory pattern: instantiate a new CacheEvent corresponding to the specified parameters.protected SafeHashMap.ValuesCollectionFactory pattern.booleanisEmpty()Returns true if this map contains no key-value mappings.booleanDetermine if incremental eviction is enabled.voidIndicates to the cache that the specified key should be loaded into the cache, if it is not already in the cache.voidloadAll()Indicates to the cache that it should load data from its loader to fill the cache; this is sometimes referred to as "pre-loading" or "warming" a cache.voidloadAll(Collection colKeys) Indicates to the cache that the specified keys should be loaded into the cache, if they are not already in the cache.Checks for a valid entry corresponding to the specified key in the cache, and returns the corresponding value if it is.peekAll(Collection colKeys) Checks for a valid entry corresponding to each specified key in the cache, and places the corresponding value in the returned map if it is.protected voidprune()Prune the cache by discarding the lowest priority cache entries.Associates the specified value with the specified key in this map.Associates the specified value with the specified key in this cache.Removes the mapping for this key from this map if present.protected booleanremoveEvicted(LocalCache.Entry entry) Remove an entry (if it is eligible for eviction) because it has expired.protected booleanremoveExpired(LocalCache.Entry entry, boolean fRemoveInternal) Deprecated.useremoveEvicted(LocalCache.Entry)insteadprotected booleanremoveIfExpired(LocalCache.Entry entry) Remove an entry if it has expired.voidremoveMapListener(MapListener listener) Remove a standard map listener that previously signed up for all events.voidremoveMapListener(MapListener listener, Filter filter) Remove a map listener that previously signed up for events based on a filter evaluation.voidremoveMapListener(MapListener listener, Object oKey) Remove a map listener that previously signed up for events about a specific key.voidReset the cache statistics.voidsetCacheLoader(CacheLoader loader) Specify the loader used by this LocalCache.voidSet the EvictionApprover for this ConfigurableCacheMap.voidSet the EvictionPolicy for the cache to use.voidsetEvictionType(int nType) Specify the eviction type for the cache.voidsetExpiryDelay(int cMillis) Specify the default "time to live" for cache entries.voidsetFlushTime(long lMillis) Deprecated.as of Coherence 3.5voidsetHighUnits(int cMax) Update the maximum size of the cache in units.voidsetIncrementalEviction(boolean fIncrementalEvict) Specify whether incremental eviction is enabled.protected voidsetKeyMask(LocalCache.KeyMask mask) ThreadLocal: Set the key mask for the current thread.voidsetLowUnits(int cMin) Specify the point to which the cache will shrink when it prunes.voidsetOptimizeGetTime(boolean fOptimize) Specify whether or not this cache is used in the environment, where theBase.getSafeTimeMillis()is used very frequently and as a result, theBase.getLastSafeTimeMillis()could be used without sacrificing the clock precision.voidsetUnitCalculator(ConfigurableCacheMap.UnitCalculator calculator) Set the UnitCalculator for the cache to use.voidsetUnitCalculatorType(int nType) Specify the unit calculator type for the cache.voidsetUnitFactor(int nFactor) Determine the factor by which the Units, LowUnits and HighUnits properties are adjusted.intsize()Returns the number of key-value mappings in this map.protected static inttoExternalUnits(long cUnits, int nFactor) Convert from an internal 64-bit unit value to an external 32-bit unit value using the configured units factor.protected static longtoInternalUnits(int cUnits, int nFactor) Convert from an external 32-bit unit value to an internal 64-bit unit value using the configured units factor.toString()For debugging purposes, format the contents of the cache as a String.protected voidtryEvict()Attempt to call evict() when no one else is, to avoid contention on opportunistic attempts at evicting.Methods inherited from class com.tangosol.util.SafeHashMap
clone, cloneEntryList, entrySet, getBucketIndex, getStableBucketArray, grow, instantiateEntry, isActiveIterator, iteratorActivated, iteratorDeactivated, keySet, removeEntryInternal, valuesMethods inherited from class java.util.AbstractMap
containsValue, equals, hashCode, putAllMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsValue, entrySet, equals, forEach, getOrDefault, hashCode, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, values
-
Field Details
-
DEFAULT_UNITS
public static final int DEFAULT_UNITSBy default, the cache size (in units) is infinite.- See Also:
-
DEFAULT_EXPIRE
public static final int DEFAULT_EXPIREBy default, the cache entries never expire.- See Also:
-
DEFAULT_KEY_MASK
The default key mask that ignores nothing. -
DEFAULT_FLUSH
public static final int DEFAULT_FLUSHDeprecated.as of Coherence 3.5By default, expired cache entries are flushed on a minute interval.- See Also:
-
DEFAULT_PRUNE
public static final double DEFAULT_PRUNEBy default, when the cache prunes, it reduces its entries to this percentage.- See Also:
-
EVICTION_POLICY_HYBRID
public static final int EVICTION_POLICY_HYBRIDBy default, the cache prunes based on a hybrid LRU+LFU algorithm.- See Also:
-
EVICTION_POLICY_LRU
public static final int EVICTION_POLICY_LRUThe cache can prune based on a pure Least Recently Used (LRU) algorithm.- See Also:
-
EVICTION_POLICY_LFU
public static final int EVICTION_POLICY_LFUThe cache can prune based on a pure Least Frequently Used (LFU) algorithm.- See Also:
-
EVICTION_POLICY_EXTERNAL
public static final int EVICTION_POLICY_EXTERNALThe cache can prune using an external eviction policy.- See Also:
-
UNIT_CALCULATOR_FIXED
public static final int UNIT_CALCULATOR_FIXEDSpecifies the default unit calculator that weighs all entries equally as 1.- See Also:
-
UNIT_CALCULATOR_BINARY
public static final int UNIT_CALCULATOR_BINARYSpecifies a unit calculator that assigns an object a weight equal to the number of bytes of memory required to cache the object.- See Also:
-
UNIT_CALCULATOR_EXTERNAL
public static final int UNIT_CALCULATOR_EXTERNALSpecifies a external (custom) unit calculator implementation.- See Also:
-
INSTANCE_HYBRID
The EvictionPolicy object for the Hybrid eviction algorithm. -
INSTANCE_LRU
The EvictionPolicy object for the Least Recently Used (LRU) eviction algorithm. -
INSTANCE_LFU
The EvictionPolicy object for the Least Frequently Used (LFU) eviction algorithm. -
INSTANCE_FIXED
The UnitCalculator object that counts each entry as one unit. -
INSTANCE_BINARY
The UnitCalculator object that measures the bytes used by entries. This is intended for caches that manage binary data. -
m_cCurUnits
protected volatile long m_cCurUnitsThe current number of units in the cache. A unit is an undefined means of measuring cached values, and must be 0 or positive. The particular Entry implementation being used defines the meaning of unit. -
m_cMaxUnits
protected long m_cMaxUnitsThe number of units to allow the cache to grow to before pruning. -
m_dflPruneLevel
protected double m_dflPruneLevelThe 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.0. -
m_cPruneUnits
protected long m_cPruneUnitsThe number of units to prune the cache down to. -
m_nUnitFactor
protected int m_nUnitFactorThe unit factor. -
m_cExpiryDelay
protected int m_cExpiryDelayThe number of milliseconds that a value will live in the cache. Zero indicates no timeout. -
m_lNextFlush
protected volatile long m_lNextFlushThe time before which a expired-entries flush will not be performed. -
m_stats
The CacheStatistics object maintained by this cache. -
m_listenerSupport
The MapListenerSupport object. -
m_nEvictionType
protected int m_nEvictionTypeThe type of eviction policy employed by the cache; one of the EVICTION_POLICY_* enumerated values. -
m_policy
The eviction policy; for eviction type EVICTION_POLICY_EXTERNAL. -
m_nCalculatorType
protected int m_nCalculatorTypeThe type of unit calculator employed by the cache; one of the UNIT_CALCULATOR_* enumerated values. -
m_calculator
The external unit calculator. -
m_arrayExpiry
Array of set of keys, indexed by the time of expiry.- Since:
- Coherence 3.5
-
m_lLastPrune
protected long m_lLastPruneThe last time that a prune was run. This value is used by the hybrid eviction policy.- Since:
- Coherence 3.5
-
m_cAvgTouch
protected int m_cAvgTouchFor a prune cycle, this value is the average number of touches that an entry should have. This value is used by the hybrid eviction policy.- Since:
- Coherence 3.5
-
m_iterEvict
For deferred eviction, iterator of entries to evict. If null, then there are no entries with deferred eviction.- Since:
- Coherence 3.5
-
m_fIncrementalEvict
protected boolean m_fIncrementalEvictSpecifies whether or not this cache will incrementally evict. -
m_apprvrEvict
The EvictionApprover. -
m_fOptimizeGetTime
protected boolean m_fOptimizeGetTimeSpecifies whether or not this cache is used in the environment, where theBase.getSafeTimeMillis()is used very frequently and as a result, theBase.getLastSafeTimeMillis()could be used without sacrificing the clock precision. By default, the optimization is off.
-
-
Constructor Details
-
LocalCache
public LocalCache()Construct the cache manager. -
LocalCache
public LocalCache(int cUnits) Construct the cache manager.- Parameters:
cUnits- the number of units that the cache manager will cache before pruning the cache
-
LocalCache
public LocalCache(int cUnits, int cExpiryMillis) Construct the cache manager.- Parameters:
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 expired
-
LocalCache
public LocalCache(int cUnits, int cExpiryMillis, double dflPruneLevel) Construct the cache manager.- Parameters:
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.0
-
LocalCache
Construct the cache manager.- Parameters:
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 expiredloader- the CacheLoader or CacheStore to use
-
-
Method Details
-
size
public int size()Description copied from class:SafeHashMapReturns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.This method is not synchronized; it returns the size at the moment that the method is invoked. To ensure that the size does not change from the returned value, the caller must synchronize on the map before calling the size method.
- Specified by:
sizein interfaceMap- Overrides:
sizein classSafeHashMap- Returns:
- the number of key-value mappings in this map
-
isEmpty
public boolean isEmpty()Description copied from class:SafeHashMapReturns true if this map contains no key-value mappings.This method is not synchronized; it returns the state of the map at the moment that the method is invoked. To ensure that the size does not change, the caller must synchronize on the map before calling the method.
- Specified by:
isEmptyin interfaceMap- Overrides:
isEmptyin classSafeHashMap- Returns:
- true if this map contains no key-value mappings
-
containsKey
Description copied from class:SafeHashMapReturns true if this map contains a mapping for the specified key.This method is not synchronized; it returns true if the map contains the key at the moment that the method is invoked. To ensure that the key is still in (or is still not in) the table when the method returns, the caller must synchronize on the map before calling the method.
- Specified by:
containsKeyin interfaceMap- Overrides:
containsKeyin classSafeHashMap- Parameters:
key- key whose presence in this map is to be tested- Returns:
- true if this map contains a mapping for the specified key
-
get
Description copied from class:SafeHashMapReturns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.- Specified by:
getin interfaceMap- Overrides:
getin classSafeHashMap- Parameters:
oKey- key whose associated value is to be returned- Returns:
- the value to which this map maps the specified key, or null if the map contains no mapping for this key
-
getCacheEntry
Description copied from interface:ConfigurableCacheMapLocate a cache Entry in the cache based on its key.- Specified by:
getCacheEntryin interfaceConfigurableCacheMap- Parameters:
oKey- the key object to search for- Returns:
- the Entry or null
-
put
Description copied from class:SafeHashMapAssociates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced.This method is not synchronized; it only synchronizes internally if it has to add a new Entry. To ensure that the value does not change (or the Entry is not removed) before this method returns, the caller must synchronize on the map before calling this method.
- Specified by:
putin interfaceCacheMap- Specified by:
putin interfaceMap- Overrides:
putin classSafeHashMap- Parameters:
oKey- key with which the specified value is to be associatedoValue- value to be associated with the specified key- Returns:
- previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values
-
put
Description copied from interface:CacheMapAssociates the specified value with the specified key in this cache. If the cache previously contained a mapping for this key, the old value is replaced. This variation of theCacheMap.put(Object oKey, Object oValue)method allows the caller to specify an expiry (or "time to live") for the cache entry.- Specified by:
putin interfaceCacheMap- Parameters:
oKey- key with which the specified value is to be associatedoValue- value to be associated with the specified keycMillis- the number of milliseconds until the cache entry will expire, also referred to as the entry's "time to live"; passCacheMap.EXPIRY_DEFAULTto use the cache's default time-to-live setting; passCacheMap.EXPIRY_NEVERto indicate that the cache entry should never expire; this milliseconds value is not a date/time value, such as is returned from System.currentTimeMillis()- Returns:
- previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values
-
clear
public void clear()Description copied from class:SafeHashMapRemoves all mappings from this map.- Specified by:
clearin interfaceMap- Overrides:
clearin classSafeHashMap
-
remove
Removes the mapping for this key from this map if present.- Specified by:
removein interfaceMap- Overrides:
removein classSafeHashMap- Parameters:
oKey- key whose mapping is to be removed from the map- Returns:
- previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values
-
addMapListener
Description copied from interface:ObservableMapAdd 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. This has the same result as the following call:addMapListener(listener, (Filter) null, false);
- Specified by:
addMapListenerin interfaceObservableMap- Parameters:
listener- theMapEventlistener to add
-
removeMapListener
Description copied from interface:ObservableMapRemove a standard map listener that previously signed up for all events. This has the same result as the following call:removeMapListener(listener, (Filter) null);
- Specified by:
removeMapListenerin interfaceObservableMap- Parameters:
listener- the listener to remove
-
addMapListener
Description copied from interface:ObservableMapAdd a map listener for a specific key.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.- Specified by:
addMapListenerin interfaceObservableMap- Parameters:
listener- theMapEventlistener to addoKey- the key that identifies the entry for which to raise eventsfLite- true to indicate that theMapEventobjects do not have to include the OldValue and NewValue property values in order to allow optimizations
-
removeMapListener
Description copied from interface:ObservableMapRemove a map listener that previously signed up for events about a specific key.- Specified by:
removeMapListenerin interfaceObservableMap- Parameters:
listener- the listener to removeoKey- the key that identifies the entry for which to raise events
-
addMapListener
Description copied from interface:ObservableMapAdd a map listener that receives events based on a filter evaluation.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.- Specified by:
addMapListenerin interfaceObservableMap- Parameters:
listener- theMapEventlistener 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 (seeMapEventFilter); null is equivalent to a filter that alway returns truefLite- true to indicate that theMapEventobjects do not have to include the OldValue and NewValue property values in order to allow optimizations
-
removeMapListener
Description copied from interface:ObservableMapRemove a map listener that previously signed up for events based on a filter evaluation.- Specified by:
removeMapListenerin interfaceObservableMap- Parameters:
listener- the listener to removefilter- the filter that was passed into the corresponding addMapListener() call
-
getUnits
public int getUnits()Description copied from interface:ConfigurableCacheMapDetermine the number of units that the cache currently stores.Note: It is expected that the return type will be widened to a long in Coherence 4.
- Specified by:
getUnitsin interfaceConfigurableCacheMap- Returns:
- the current size of the cache in units
-
getHighUnits
public int getHighUnits()Description copied from interface:ConfigurableCacheMapDetermine the limit of the cache size in units. The cache will prune itself automatically once it reaches its maximum unit level. This is often referred to as the "high water mark" of the cache.Note: It is expected that the return type will be widened to a long in Coherence 4.
- Specified by:
getHighUnitsin interfaceConfigurableCacheMap- Returns:
- the limit of the cache size in units
-
setHighUnits
public void setHighUnits(int cMax) Description copied from interface:ConfigurableCacheMapUpdate the maximum size of the cache in units. This is often referred to as the "high water mark" of the cache.Note: It is expected that the parameter will be widened to a long in Coherence 4.
- Specified by:
setHighUnitsin interfaceConfigurableCacheMap- Parameters:
cMax- the new maximum size of the cache, in units
-
getLowUnits
public int getLowUnits()Description copied from interface:ConfigurableCacheMapDetermine the point to which the cache will shrink when it prunes. This is often referred to as a "low water mark" of the cache. If the cache incrementally prunes, then this setting will have no effect.Note: It is expected that the parameter will be widened to a long in Coherence 4.
- Specified by:
getLowUnitsin interfaceConfigurableCacheMap- Returns:
- the number of units that the cache prunes to
-
setLowUnits
public void setLowUnits(int cMin) Description copied from interface:ConfigurableCacheMapSpecify the point to which the cache will shrink when it prunes. This is often referred to as a "low water mark" of the cache.Note: It is expected that the parameter will be widened to a long in Coherence 4.
- Specified by:
setLowUnitsin interfaceConfigurableCacheMap- Parameters:
cMin- the number of units that the cache prunes to
-
getUnitFactor
public int getUnitFactor()Description copied from interface:ConfigurableCacheMapDetermine the factor by which the Units, LowUnits and HighUnits properties are adjusted. Using a binary unit calculator, for example, the factor 1048576 could be used to count megabytes instead of bytes.Note: This property exists only to avoid changing the type of the units, low units and high units properties from 32-bit values to 64-bit values. It is expected that the parameter will be dropped in Coherence 4.
- Specified by:
getUnitFactorin interfaceConfigurableCacheMap- Returns:
- the units factor; the default is 1
-
setUnitFactor
public void setUnitFactor(int nFactor) Description copied from interface:ConfigurableCacheMapDetermine the factor by which the Units, LowUnits and HighUnits properties are adjusted. Using a binary unit calculator, for example, the factor 1048576 could be used to count megabytes instead of bytes.Note: This property exists only to avoid changing the type of the units, low units and high units properties from 32-bit values to 64-bit values. It is expected that the parameter will be dropped in Coherence 4.
- Specified by:
setUnitFactorin interfaceConfigurableCacheMap- Parameters:
nFactor- the units factor; the default is 1
-
getEvictionPolicy
Description copied from interface:ConfigurableCacheMapObtain the current EvictionPolicy used by the cache.- Specified by:
getEvictionPolicyin interfaceConfigurableCacheMap- Returns:
- the EvictionPolicy used by the cache
-
setEvictionPolicy
Description copied from interface:ConfigurableCacheMapSet the EvictionPolicy for the cache to use.- Specified by:
setEvictionPolicyin interfaceConfigurableCacheMap- Parameters:
policy- an EvictionPolicy
-
getEvictionApprover
Description copied from interface:ConfigurableCacheMapObtain the registered EvictionApprover.- Specified by:
getEvictionApproverin interfaceConfigurableCacheMap- Returns:
- the EvictionApprover (could be null)
-
setEvictionApprover
Description copied from interface:ConfigurableCacheMapSet the EvictionApprover for this ConfigurableCacheMap.- Specified by:
setEvictionApproverin interfaceConfigurableCacheMap- Parameters:
approver- the EvictionApprover
-
getUnitCalculatorType
public int getUnitCalculatorType()Determine the current unit calculator type.- Returns:
- one of the UNIT_CALCULATOR_* enumerated values
-
getUnitCalculator
Description copied from interface:ConfigurableCacheMapObtain the current UnitCalculator used by the cache.- Specified by:
getUnitCalculatorin interfaceConfigurableCacheMap- Returns:
- the UnitCalculator used by the cache
-
setUnitCalculator
Description copied from interface:ConfigurableCacheMapSet the UnitCalculator for the cache to use.- Specified by:
setUnitCalculatorin interfaceConfigurableCacheMap- Parameters:
calculator- a UnitCalculator
-
setUnitCalculatorType
public void setUnitCalculatorType(int nType) Specify the unit calculator type for the cache. The type can only be set to an external unit calculator if a UnitCalculator object has been provided.- Parameters:
nType- one of the UNIT_CALCULATOR_* enumerated values
-
getExpiryDelay
public int getExpiryDelay()Description copied from interface:ConfigurableCacheMapDetermine the default "time to live" for each individual cache entry.- Specified by:
getExpiryDelayin interfaceConfigurableCacheMap- Returns:
- the number of milliseconds that a cache entry value will live, or zero if cache entries are never automatically expired
-
setExpiryDelay
public void setExpiryDelay(int cMillis) Description copied from interface:ConfigurableCacheMapSpecify the default "time to live" for cache entries. This does not affect the already-scheduled expiry of existing entries.- Specified by:
setExpiryDelayin interfaceConfigurableCacheMap- Parameters:
cMillis- the number of milliseconds that cache entries will live, or zero to disable automatic expiry
-
getNextExpiryTime
public long getNextExpiryTime()Description copied from interface:ConfigurableCacheMapDetermine the next expiry time for the cache entries. This value is supposed to be used only by the "active" expiry algorithms, so for implementations that choose to return the value of zero the entries will be evicted as with pre-existing "passive" expiry approach.- Specified by:
getNextExpiryTimein interfaceConfigurableCacheMap- Returns:
- the earliest time (using the
SafeClock) that one or more cache entries will expire or zero if the cache is empty, its entries never expire or the implementation chooses to avoid the pro-active eviction
-
evict
Evict a specified key from the cache, as if it had expired from the cache. If the key is not in the cache or the entry is not eligible for eviction, then this method has no effect.- Specified by:
evictin interfaceConfigurableCacheMap- Parameters:
oKey- the key to evict from the cache
-
evictAll
Description copied from interface:ConfigurableCacheMapEvict the specified keys from the cache, as if they had each expired from the cache.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); }- Specified by:
evictAllin interfaceConfigurableCacheMap- Parameters:
colKeys- a collection of keys to evict from the cache
-
evict
public void evict()Description copied from interface:ConfigurableCacheMapEvict 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.- Specified by:
evictin interfaceConfigurableCacheMap
-
getCacheLoader
Determine the loader used by this LocalCache, if any.- Returns:
- the loader used by this LocalCache, or null if none
-
setCacheLoader
Specify the loader used by this LocalCache.- Parameters:
loader- loader to use, or null
-
getEntry
Locate an Entry in the hash map based on its key. If the Entry is not in the cache, load the Entry for the specified key and return it.- Overrides:
getEntryin classSafeHashMap- Parameters:
oKey- the key to the desired cached Entry- Returns:
- the Entry corresponding to the specified key, otherwise null
-
getAll
Get all the specified keys, if they are in the cache. For each key that is in the cache, that key and its corresponding value will be placed in the map that is returned by this method. The absence of a key in the returned map indicates that it was not in the cache, which may imply (for caches that can load behind the scenes) that the requested data could not be loaded.The result of this method is defined to be semantically the same as the following implementation, without regards to threading issues:
Map map = new AnyMap(); // could be hash map or ... for (Iterator iter = col.iterator(); iter.hasNext(); ) { Object oKey = iter.next(); Object oVal = get(oKey); if (oVal != null || containsKey(oKey)) { map.put(oKey, oVal); } } return map; -
load
Indicates to the cache that the specified key should be loaded into the cache, if it is not already in the cache. This provides a means to "pre-load" a single entry into the cache using the cache's loader.If a valid entry with the specified key already exists in the cache, or if the cache does not have a loader, then this method has no effect.
An implementation may perform the load operation asynchronously.
- Parameters:
oKey- the key to request to be loaded
-
loadAll
public void loadAll()Indicates to the cache that it should load data from its loader to fill the cache; this is sometimes referred to as "pre-loading" or "warming" a cache.The specific set of data that will be loaded is unspecified. The implementation may choose to load all data, some specific subset of the data, or no data. An implementation may require that the loader implement the IterableCacheLoader interface in order for this method to load any data.
An implementation may perform the load operation asynchronously.
-
loadAll
Indicates to the cache that the specified keys should be loaded into the cache, if they are not already in the cache. This provides a means to "pre-load" entries into the cache using the cache's loader.The result of this method is defined to be semantically the same as the following implementation:
CacheLoader loader = getCacheLoader(); if (loader != null && !colKeys.isEmpty()) { Set setRequest = new HashSet(colKeys); setRequest.removeAll(peekAll(colKeys).keySet()); if (!setRequest.isEmpty()) { Map map = loader.loadAll(colKeys); if (!map.isEmpty()) { putAll(map); } } }- Parameters:
colKeys- a collection of keys to request to be loaded
-
peek
Checks for a valid entry corresponding to the specified key in the cache, and returns the corresponding value if it is. If it is not in the cache, returns null, and does not attempt to load the value using its cache loader.- Parameters:
oKey- the key to "peek" into the cache for- Returns:
- the value corresponding to the specified key
-
peekAll
Checks for a valid entry corresponding to each specified key in the cache, and places the corresponding value in the returned map if it is. For each key that is not in the cache, no entry is placed into the returned map. The cache does not attempt to load any values using its cache loader.The result of this method is defined to be semantically the same as the following implementation, without regards to threading issues:
Map map = new HashMap(); for (Iterator iter = colKeys.iterator(); iter.hasNext(); ) { Object oKey = iter.next(); Object oValue = peek(oKey); if (oValue != null || containsKey(oKey)) { map.put(oKey, oValue); } } return map;- Parameters:
colKeys- a collection of keys to "peek" into the cache for- Returns:
- a Map of keys that were found in the cache and their values
-
instantiateEntrySet
Factory pattern.- Overrides:
instantiateEntrySetin classSafeHashMap- Returns:
- a new instance of the EntrySet class (or a subclass thereof)
-
instantiateKeySet
Factory pattern.- Overrides:
instantiateKeySetin classSafeHashMap- Returns:
- a new instance of the KeySet class (or subclass thereof)
-
instantiateValuesCollection
Factory pattern.- Overrides:
instantiateValuesCollectionin classSafeHashMap- Returns:
- a new instance of the ValuesCollection class (or subclass thereof)
-
toString
For debugging purposes, format the contents of the cache as a String.- Overrides:
toStringin classAbstractMap- Returns:
- a String representation of the cache contents
-
toInternalUnits
protected static long toInternalUnits(int cUnits, int nFactor) Convert from an external 32-bit unit value to an internal 64-bit unit value using the configured units factor.- Parameters:
cUnits- an external 32-bit units valuenFactor- the unit factor- Returns:
- an internal 64-bit units value
-
toExternalUnits
protected static int toExternalUnits(long cUnits, int nFactor) Convert from an internal 64-bit unit value to an external 32-bit unit value using the configured units factor.- Parameters:
cUnits- an internal 64-bit units valuenFactor- the unit factor- Returns:
- an external 32-bit units value
-
getEvictionType
public int getEvictionType()Determine the current eviction type.- Returns:
- one of the EVICTION_POLICY_* enumerated values
-
setEvictionType
public void setEvictionType(int nType) Specify the eviction type for the cache. The type can only be set to an external policy if an EvictionPolicy object has been provided.- Parameters:
nType- one of the EVICTION_POLICY_* enumerated values
-
getFlushTime
public long getFlushTime()Deprecated.as of Coherence 3.5Determine the date/time at which the next cache flush is scheduled. Note that the date/time may be Long.MAX_VALUE, which implies that a flush will never occur. Also note that the cache may internally adjust the flush time to prevent a flush from occurring during certain processing as a means to raise concurrency.- Returns:
- the date/time value, in milliseconds, when the cache will next automatically flush
-
setFlushTime
public void setFlushTime(long lMillis) Deprecated.as of Coherence 3.5Specify the date/time at which the next cache flush is to occur. Note that the date/time may be Long.MAX_VALUE, which implies that a flush will never occur. A time in the past or at the present will cause an immediate flush.- Parameters:
lMillis- the date/time value, in milliseconds, when the cache should next automatically flush
-
isIncrementalEviction
public boolean isIncrementalEviction()Determine if incremental eviction is enabled. (Incremental eviction is not supported for custom eviction policies.)- Returns:
- true if eviction is incremental; false if it is done in bulk
- Since:
- Coherence 3.5
-
setIncrementalEviction
public void setIncrementalEviction(boolean fIncrementalEvict) Specify whether incremental eviction is enabled.- Parameters:
fIncrementalEvict- pass true to enable incremental eviction; false to disable incremental eviction- Since:
- Coherence 3.5
-
getCacheStatistics
Returns the CacheStatistics for this cache.- Returns:
- a CacheStatistics object
-
getCacheHits
public long getCacheHits()Determine the rough number of cache hits since the cache statistics were last reset.- Returns:
- the number of
get(java.lang.Object)calls that have been served by existing cache entries
-
getCacheMisses
public long getCacheMisses()Determine the rough number of cache misses since the cache statistics were last reset.- Returns:
- the number of
get(java.lang.Object)calls that failed to find an existing cache entry because the requested key was not in the cache
-
getHitProbability
public double getHitProbability()Determine the rough probability (0 <= p <= 1) that any particularget(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.- Returns:
- the cache hit probability (0 <= p <= 1)
-
resetHitStatistics
public void resetHitStatistics()Reset the cache statistics. -
tryEvict
protected void tryEvict()Attempt to call evict() when no one else is, to avoid contention on opportunistic attempts at evicting. -
configureEviction
Configure the eviction type and policy.- Parameters:
nType- one of the EVICTION_POLICY_* enumerated valuespolicy- an external eviction policy, or null
-
configureUnitCalculator
Configure the unit calculator type and implementation.- Parameters:
nType- one of the UNIT_CALCULATOR_* enumerated valuescalculator- an external unit calculator, or null
-
getEntryInternal
Description copied from class:SafeHashMapLocate an Entry in the hash map based on its key.Unlike the
SafeHashMap.getEntry(java.lang.Object)method, there must be no side-effects of calling this method.- Overrides:
getEntryInternalin classSafeHashMap- Parameters:
oKey- the key object to search for- Returns:
- the Entry or null
-
getCacheStore
Determine the store used by this LocalCache, if any.- Returns:
- the CacheStore used by this LocalCache, or null if none
-
getKeyMask
ThreadLocal: Get the current key mask for the current thread.- Returns:
- the current key mask
-
setKeyMask
ThreadLocal: Set the key mask for the current thread.- Parameters:
mask- the new key mask, or null to clear the mask
-
removeEvicted
Remove an entry (if it is eligible for eviction) because it has expired.- Parameters:
entry- the expired cache entry- Returns:
- true iff the entry was removed
-
instantiateMapEvent
Factory pattern: instantiate a new CacheEvent corresponding to the specified parameters.- Returns:
- a new instance of the CacheEvent class (or a subclass thereof)
-
removeExpired
Deprecated.useremoveEvicted(LocalCache.Entry)insteadRemove an entry (if it is eligible for eviction) because it has expired.Note: This method is the same as
removeEvicted(LocalCache.Entry)and is left for backward compatibility.- Parameters:
entry- the expired cache entryfRemoveInternal- true if the cache entry still needs to be removed from the cache- Returns:
- true iff the entry was removed
-
removeIfExpired
Remove an entry if it has expired.- Parameters:
entry- the entry- Returns:
- true iff the entry was actually removed
-
adjustUnits
protected void adjustUnits(int cDelta) Adjust current size.- Parameters:
cDelta- the delta units to adjust to
-
prune
protected void prune()Prune the cache by discarding the lowest priority cache entries. -
checkFlush
protected void checkFlush()Deprecated.as of Coherence 3.5, useevict()Check if any entries in the cache have expired, and evict them if they have. -
getMapListenerSupport
Accessor for the MapListenerSupport for sub-classes.- Returns:
- the MapListenerSupport, or null if there are no listeners
-
hasListeners
protected boolean hasListeners()Determine if the LocalCache has any listeners at all.- Returns:
- true iff this LocalCache has at least one MapListener
-
dispatchEvent
Dispatch the passed event.- Parameters:
evt- a CacheEvent object
-
getCurrentTimeMillis
public long getCurrentTimeMillis()Return the currentsafe timeorlast safe timedepending on the optimization flag.- Returns:
- the current time
-
setOptimizeGetTime
public void setOptimizeGetTime(boolean fOptimize) Specify whether or not this cache is used in the environment, where theBase.getSafeTimeMillis()is used very frequently and as a result, theBase.getLastSafeTimeMillis()could be used without sacrificing the clock precision. By default, the optimization is off.- Parameters:
fOptimize- pass true to turn the "last safe time" optimization on
-
instantiateInternalListener
Factory pattern: Instantiate an internal MapListener to listen to this cache and report changes to the CacheStore.- Returns:
- a new MapListener instance
-
instantiateEntry
Factory method. This method exists to allow the LocalCache class to be easily inherited from by allowing the Entry class to be easily sub-classed.- Overrides:
instantiateEntryin classSafeHashMap- Returns:
- an instance of Entry that holds the passed cache value
-