Class SerializationCache
- All Implemented Interfaces:
CacheMap,ConfigurableCacheMap,ObservableMap,Map
This implementation is partially thread safe. It assumes that multiple threads will not be accessing the same keys at the same time, nor would any other thread be accessing this cache while a clear() operation were going on, for example. In other words, this implementation assumes that access to this cache is either single-threaded or gated through an object like WrapperConcurrentMap.
The primary reason why SerializationCache is a sub-class of SerializationMap instead of combining their functionality is that SerializationMap represents a passive store, and thus does not implement the ObservableMap interface, while SerializationCache represents an active store, and thus clients of it would have to always handle potential events, even if it were not size-limited.
- Since:
- Coherence 2.2
- Author:
- cp 2003.05.28
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classA class that holds on to the expiry time and touch order for an entry.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.Nested classes/interfaces inherited from class com.tangosol.util.AbstractKeySetBasedMap
AbstractKeySetBasedMap.KeyIterator, AbstractKeySetBasedMap.KeySet, AbstractKeySetBasedMap.ValuesCollectionNested classes/interfaces inherited from class com.tangosol.util.AbstractKeyBasedMap
AbstractKeyBasedMap.DeferredCacheEvent<K,V> Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriterNested classes/interfaces inherited from interface com.tangosol.net.cache.ConfigurableCacheMap
ConfigurableCacheMap.Entry, ConfigurableCacheMap.EvictionApprover, ConfigurableCacheMap.EvictionPolicy, ConfigurableCacheMap.UnitCalculator -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConfigurableCacheMap.EvictionApproverThe EvictionApprover.protected ConfigurableCacheMap.UnitCalculatorThe unit calculator to use to limit size of the cache.protected longCurrent number of units to in the cache.protected longMaximum number of units to manage in the cache.protected longThe number of units to prune the cache down to.protected intThe unit factor.Fields inherited from class com.tangosol.util.Base
DEFAULT_LOAD_FACTOR, LOG_ALWAYS, LOG_CONFIG, LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_MAX, LOG_MIN, LOG_QUIET, LOG_WARN, POWER_0, POWER_G, POWER_K, POWER_M, POWER_T, UNIT_D, UNIT_H, UNIT_M, UNIT_MS, UNIT_NS, UNIT_S, UNIT_USFields inherited from interface com.tangosol.net.cache.CacheMap
EXPIRY_DEFAULT, EXPIRY_NEVER -
Constructor Summary
ConstructorsConstructorDescriptionSerializationCache(BinaryStore store, int cMax) Construct a SerializationCache on top of a BinaryStore.SerializationCache(BinaryStore store, int cMax, boolean fBinaryMap) Construct a SerializationCache on top of a BinaryStore.SerializationCache(BinaryStore store, int cMax, ClassLoader loader) Construct a SerializationCache on top of a BinaryStore. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidMake sure that the cache does not contain expired items.protected voidMake sure the size of the cache isn't too big.voidclear()Clear all key/value mappings.booleancontainsKey(Object oKey) Returns true if this map contains a mapping for the specified key.booleancontainsValue(Object oValue) Returns true if this Map maps one or more keys to the specified value.voidevict()Flush items that have expired.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.voidflush()Deprecated.Returns the value to which this map maps the specified key.getCacheEntry(Object oKey) Locate a cache Entry in the cache based on its key.protected StringAssemble a human-readable description.Obtain the registered EvictionApprover.Obtain the current EvictionPolicy used by the cache.protected LongArrayGet the Expiry data structure.intDetermine the default "time to live" for each individual cache entry.intDetermine the limit of the cache size in units.intDetermine the point to which the cache will shrink when it prunes.protected LongArrayGet the LRU data structure.longDetermine the next expiry time for the cache entries.protected longDetermine the next value from the touch counter.Obtain the current UnitCalculator used by the cache.intDetermine the factor by which the Units, LowUnits and HighUnits properties are adjusted.intgetUnits()Determine the number of units that the cache currently stores.instantiateEntryAttributes(SerializationCache.EntryAttributes attrOrig, long ldtExpires, long nTouch, int cUnits) Factory pattern: Construct an attribute holder for an entry.protected SetFactory pattern: Create a Set that represents the entries in the Map.booleanisEmpty()Returns true if this map contains no key-value mappings.Associates the specified value with the specified key in this map.Associates the specified value with the specified key in this cache.voidCopies all of the mappings from the specified map to this map.protected voidregisterKey(Object oKey, Binary binKey, Binary binValue) Register a new key for the SerializationMap.protected voidregisterKey(Object oKey, Binary binKey, Binary binValue, int cMillis) Register a new key for the SerializationMap.Removes the mapping for this key from this map if present.protected booleanremoveBlind(Object oKey) Removes the mapping for this key from this map if present.protected voidsetBinaryStore(BinaryStore store) Configures the BinaryStore that this map will use for its storage.voidSet the EvictionApprover for this ConfigurableCacheMap.voidSet the EvictionPolicy for the cache to use.voidsetExpiryDelay(int cMillis) Specify the default "time to live" for cache entries.voidsetHighUnits(int cMax) Update the maximum size of the cache in units.voidsetLowUnits(int cUnits) Specify the point to which the cache will shrink when it prunes.voidsetUnitCalculator(ConfigurableCacheMap.UnitCalculator calculator) Set the UnitCalculator for the cache to use.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.toString()Returns a string representation of this Map.protected voidTouch an object to pop it to the top of the LRUprotected voidunregisterKey(Object oKey) Unregister a key from the SerializationMap.Methods inherited from class com.tangosol.net.cache.AbstractSerializationCache
addMapListener, addMapListener, addMapListener, dispatchEvent, dispatchPendingEvent, getMapListenerSupport, hasListeners, removeMapListener, removeMapListener, removeMapListenerMethods inherited from class com.tangosol.net.cache.SerializationMap
eraseStore, fromBinary, getBinaryStore, getCacheStatistics, getClassLoader, getInternalKeySet, getKeyMap, instantiateKeyMap, isBinaryMap, setBinaryMap, setClassLoader, toBinaryMethods inherited from class com.tangosol.util.AbstractKeySetBasedMap
instantiateKeyIterator, instantiateKeySet, instantiateValues, isInternalKeySetIteratorMutable, iterateKeysMethods inherited from class com.tangosol.util.AbstractKeyBasedMap
clone, entrySet, equals, getAll, hashCode, keySet, valuesMethods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, newHashMap, newHashMap, newHashSet, newHashSet, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, waitMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, entrySet, equals, forEach, getOrDefault, hashCode, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll, valuesMethods inherited from interface com.tangosol.util.ObservableMap
addMapListener, addMapListener, addMapListener, removeMapListener, removeMapListener, removeMapListener
-
Field Details
-
m_cMaxUnits
protected long m_cMaxUnitsMaximum number of units to manage in the cache. -
m_cCurUnits
protected long m_cCurUnitsCurrent number of units to in the cache. -
m_cPruneUnits
protected long m_cPruneUnitsThe number of units to prune the cache down to. -
m_calculator
The unit calculator to use to limit size of the cache. -
m_nUnitFactor
protected int m_nUnitFactorThe unit factor. -
m_apprvrEvict
The EvictionApprover.
-
-
Constructor Details
-
SerializationCache
Construct a SerializationCache on top of a BinaryStore.- Parameters:
store- the BinaryStore to use to write the serialized objects tocMax- the maximum number of items to store in the binary store
-
SerializationCache
Construct a SerializationCache on top of a BinaryStore.- Parameters:
store- the BinaryStore to use to write the serialized objects tocMax- the maximum number of items to store in the binary storeloader- the ClassLoader to use for deserialization
-
SerializationCache
Construct a SerializationCache on top of a BinaryStore.- Parameters:
store- the BinaryStore to use to write the serialized objects tocMax- the maximum number of items to store in the binary storefBinaryMap- true indicates that this map will only manage binary keys and values- Since:
- Coherence 2.4
-
-
Method Details
-
clear
public void clear()Clear all key/value mappings.- Specified by:
clearin interfaceMap- Overrides:
clearin classAbstractSerializationCache
-
containsKey
Returns true if this map contains a mapping for the specified key.- Specified by:
containsKeyin interfaceMap- Overrides:
containsKeyin classAbstractKeySetBasedMap- Returns:
- true if this map contains a mapping for the specified key, false otherwise.
-
containsValue
Returns true if this Map maps one or more keys to the specified value.- Specified by:
containsValuein interfaceMap- Overrides:
containsValuein classSerializationMap- Returns:
- true if this Map maps one or more keys to the specified value, false otherwise
-
get
Returns the value to which this map maps the specified key.- Specified by:
getin interfaceMap- Overrides:
getin classSerializationMap- Parameters:
oKey- the key object- Returns:
- the value to which this map maps the specified key, or null if the map contains no mapping for this key
-
isEmpty
public boolean isEmpty()Returns true if this map contains no key-value mappings.- Specified by:
isEmptyin interfaceMap- Overrides:
isEmptyin classAbstractKeySetBasedMap- Returns:
- true if this map contains no key-value mappings
-
put
Associates the specified value with the specified key in this map.- Specified by:
putin interfaceCacheMap- Specified by:
putin interfaceMap- Overrides:
putin classAbstractSerializationCache- 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
-
putAll
Copies all of the mappings from the specified map to this map. The effect of this call is equivalent to that of callingAbstractKeyBasedMap.put(K, V)on this map once for each mapping in the passed map. The behavior of this operation is unspecified if the passed map is modified while the operation is in progress.- Specified by:
putAllin interfaceMap- Overrides:
putAllin classAbstractSerializationCache- Parameters:
map- the Map containing the key/value pairings to put into this Map
-
remove
Removes the mapping for this key from this map if present. Expensive: updates both the underlying cache and the local cache.- Specified by:
removein interfaceMap- Overrides:
removein classAbstractSerializationCache- 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.
-
size
public int size()Returns the number of key-value mappings in this map.- Specified by:
sizein interfaceMap- Overrides:
sizein classAbstractKeySetBasedMap- Returns:
- the number of key-value mappings in this map
-
removeBlind
Removes the mapping for this key from this map if present. This method exists to allow sub-classes to optimize remove functionality for situations in which the original value is not required.- Overrides:
removeBlindin classAbstractSerializationCache- Parameters:
oKey- key whose mapping is to be removed from the map- Returns:
- true iff the Map changed as the result of this operation
-
put
Associates 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
-
getUnits
public int getUnits()Determine 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()Determine 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) Update 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()Determine 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 cUnits) Specify 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:
cUnits- the number of units that the cache prunes to
-
getUnitFactor
public int getUnitFactor()Determine 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) Determine 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
Obtain the current EvictionPolicy used by the cache.- Specified by:
getEvictionPolicyin interfaceConfigurableCacheMap- Returns:
- the EvictionPolicy used by the cache
-
setEvictionPolicy
Set the EvictionPolicy for the cache to use.- Specified by:
setEvictionPolicyin interfaceConfigurableCacheMap- Parameters:
policy- an EvictionPolicy
-
evict
Evict a specified key from the cache, as if it had expired from the cache. If the key is not in the cache, then the method has no effect.- Specified by:
evictin interfaceConfigurableCacheMap- Parameters:
oKey- the key to evict from the cache
-
evictAll
Evict 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()Flush items that have expired.- Specified by:
evictin interfaceConfigurableCacheMap- Specified by:
evictin classAbstractSerializationCache
-
getExpiryDelay
public int getExpiryDelay()Determine 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) Specify 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()Determine 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
-
getEvictionApprover
Obtain the registered EvictionApprover.- Specified by:
getEvictionApproverin interfaceConfigurableCacheMap- Returns:
- the EvictionApprover (could be null)
-
setEvictionApprover
Set the EvictionApprover for this ConfigurableCacheMap.- Specified by:
setEvictionApproverin interfaceConfigurableCacheMap- Parameters:
approver- the EvictionApprover
-
getCacheEntry
Locate 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
-
getUnitCalculator
Obtain the current UnitCalculator used by the cache.- Specified by:
getUnitCalculatorin interfaceConfigurableCacheMap- Returns:
- the UnitCalculator used by the cache
-
setUnitCalculator
Set the UnitCalculator for the cache to use.- Specified by:
setUnitCalculatorin interfaceConfigurableCacheMap- Parameters:
calculator- a UnitCalculator
-
flush
public void flush()Deprecated.useevict()Flush items that have expired. -
toString
Returns a string representation of this Map. The string representation consists of a list of key-value mappings in the order returned by the Map's entrySet view's iterator, enclosed in braces ("{}"). Adjacent mappings are separated by the characters ", " (comma and space). Each key-value mapping is rendered as the key followed by an equals sign ("=") followed by the associated value. Keys and values are converted to strings as by String.valueOf(Object).- Overrides:
toStringin classSerializationMap- Returns:
- a String representation of this Map
-
setBinaryStore
Configures the BinaryStore that this map will use for its storage.- Overrides:
setBinaryStorein classSerializationMap- Parameters:
store- the BinaryStore to use
-
getTouchCounter
protected long getTouchCounter()Determine the next value from the touch counter.- Returns:
- the next value from the touch counter
-
getLruArray
Get the LRU data structure. The key is a touch count, the value is the Object key for the cache.- Returns:
- the LRU data structure
-
getExpiryArray
Get the Expiry data structure. The key is a date/time value, the value is a set of Object keys for the cache that expire at that time.- Returns:
- the Expiry data structure
-
getDescription
Assemble a human-readable description.- Overrides:
getDescriptionin classAbstractSerializationCache- Returns:
- a description of this Map
-
registerKey
Register a new key for the SerializationMap. This method maintains the internal key Set for the SerializationMap.- Overrides:
registerKeyin classSerializationMap- Parameters:
oKey- the key that has been added to the mapbinKey- the binary form of the keybinValue- the binary form of the value
-
registerKey
Register a new key for the SerializationMap. This method maintains the internal key Set for the SerializationMap.- Parameters:
oKey- the key that has been added to the mapbinKey- the binary form of the key (null if only TTL change)binValue- the binary form of the value (null if only TTL change)cMillis- the TTL value (in milliseconds) for the entry
-
touch
Touch an object to pop it to the top of the LRU- Parameters:
oKey- the key of the object to touch
-
unregisterKey
Unregister a key from the SerializationMap. This method maintains the internal key Set for the SerializationMap.- Overrides:
unregisterKeyin classSerializationMap- Parameters:
oKey- the key that has been removed from the map
-
checkSize
protected void checkSize()Make sure the size of the cache isn't too big. -
checkExpiry
protected void checkExpiry()Make sure that the cache does not contain expired items. -
instantiateEntryAttributes
public SerializationCache.EntryAttributes instantiateEntryAttributes(SerializationCache.EntryAttributes attrOrig, long ldtExpires, long nTouch, int cUnits) Factory pattern: Construct an attribute holder for an entry.- Parameters:
attrOrig- the previous attributes for this entry, if anyldtExpires- the date/time at which the entry expires, or zeronTouch- the touch counter assigned to the entrycUnits- the number of storage units used by the entry- Returns:
- the instantiated
SerializationCache.EntryAttributes
-
instantiateEntrySet
Factory pattern: Create a Set that represents the entries in the Map.- Overrides:
instantiateEntrySetin classAbstractKeySetBasedMap- Returns:
- a new instance of Set that represents the entries in the Map
-
evict()