public class SerializationCache extends AbstractSerializationCache implements CacheMap, ConfigurableCacheMap
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.
| Modifier and Type | Class and Description |
|---|---|
protected class |
SerializationCache.EntryAttributes
A class that holds on to the expiry time and touch order for an entry.
|
class |
SerializationCache.EntrySet
A set of entries backed by this map.
|
static class |
SerializationCache.InternalEvictionPolicy
The InternalEvictionPolicy represents a pluggable eviction policy for the non-pluggable built-in (internal) eviction policies supported by this cache implementation.
|
AbstractKeySetBasedMap.KeyIterator, AbstractKeySetBasedMap.KeySet, AbstractKeySetBasedMap.ValuesCollectionAbstractKeyBasedMap.DeferredCacheEvent<K,V>Base.LoggingWriter, Base.StackFrameConfigurableCacheMap.Entry, ConfigurableCacheMap.EvictionApprover, ConfigurableCacheMap.EvictionPolicy, ConfigurableCacheMap.UnitCalculator| Modifier and Type | Field and Description |
|---|---|
protected ConfigurableCacheMap.EvictionApprover |
m_apprvrEvict
The EvictionApprover.
|
protected ConfigurableCacheMap.UnitCalculator |
m_calculator
The unit calculator to use to limit size of the cache.
|
protected long |
m_cCurUnits
Current number of units to in the cache.
|
protected long |
m_cMaxUnits
Maximum number of units to manage in the cache.
|
protected long |
m_cPruneUnits
The number of units to prune the cache down to.
|
protected int |
m_nUnitFactor
The unit factor.
|
LOG_ALWAYS, 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_USEXPIRY_DEFAULT, EXPIRY_NEVER| Constructor and Description |
|---|
SerializationCache(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.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkExpiry()
Make sure that the cache does not contain expired items.
|
protected void |
checkSize()
Make sure the size of the cache isn't too big.
|
void |
clear()
Clear all key/value mappings.
|
boolean |
containsKey(Object oKey)
Returns true if this map contains a mapping for the specified key.
|
boolean |
containsValue(Object oValue)
Returns true if this Map maps one or more keys to the specified value.
|
void |
evict()
Flush items that have expired.
|
void |
evict(Object oKey)
Evict a specified key from the cache, as if it had expired from the cache.
|
void |
evictAll(Collection colKeys)
Evict the specified keys from the cache, as if they had each expired from the cache.
|
void |
flush()
Deprecated.
use
evict() |
Object |
get(Object oKey)
Returns the value to which this map maps the specified key.
|
ConfigurableCacheMap.Entry |
getCacheEntry(Object oKey)
Locate a cache Entry in the cache based on its key.
|
protected String |
getDescription()
Assemble a human-readable description.
|
ConfigurableCacheMap.EvictionApprover |
getEvictionApprover()
Obtain the registered EvictionApprover.
|
ConfigurableCacheMap.EvictionPolicy |
getEvictionPolicy()
Obtain the current EvictionPolicy used by the cache.
|
protected LongArray |
getExpiryArray()
Get the Expiry data structure.
|
int |
getExpiryDelay()
Determine the default "time to live" for each individual cache entry.
|
int |
getHighUnits()
Determine the limit of the cache size in units.
|
int |
getLowUnits()
Determine the point to which the cache will shrink when it prunes.
|
protected LongArray |
getLruArray()
Get the LRU data structure.
|
long |
getNextExpiryTime()
Determine the next expiry time for the cache entries.
|
protected long |
getTouchCounter()
Determine the next value from the touch counter.
|
ConfigurableCacheMap.UnitCalculator |
getUnitCalculator()
Obtain the current UnitCalculator used by the cache.
|
int |
getUnitFactor()
Determine the factor by which the Units, LowUnits and HighUnits properties are adjusted.
|
int |
getUnits()
Determine the number of units that the cache currently stores.
|
SerializationCache.EntryAttributes |
instantiateEntryAttributes(SerializationCache.EntryAttributes attrOrig, long ldtExpires, long nTouch, int cUnits)
Factory pattern: Construct an attribute holder for an entry.
|
protected Set |
instantiateEntrySet()
Factory pattern: Create a Set that represents the entries in the Map.
|
boolean |
isEmpty()
Returns true if this map contains no key-value mappings.
|
Object |
put(Object oKey, Object oValue)
Associates the specified value with the specified key in this map.
|
Object |
put(Object oKey, Object oValue, long cMillis)
Associates the specified value with the specified key in this cache.
|
void |
putAll(Map map)
Copies all of the mappings from the specified map to this map.
|
protected void |
registerKey(Object oKey, Binary binKey, Binary binValue)
Register a new key for the SerializationMap.
|
protected void |
registerKey(Object oKey, Binary binKey, Binary binValue, int cMillis)
Register a new key for the SerializationMap.
|
Object |
remove(Object oKey)
Removes the mapping for this key from this map if present.
|
protected boolean |
removeBlind(Object oKey)
Removes the mapping for this key from this map if present.
|
protected void |
setBinaryStore(BinaryStore store)
Configures the BinaryStore that this map will use for its storage.
|
void |
setEvictionApprover(ConfigurableCacheMap.EvictionApprover approver)
Set the EvictionApprover for this ConfigurableCacheMap.
|
void |
setEvictionPolicy(ConfigurableCacheMap.EvictionPolicy policy)
Set the EvictionPolicy for the cache to use.
|
void |
setExpiryDelay(int cMillis)
Specify the default "time to live" for cache entries.
|
void |
setHighUnits(int cMax)
Update the maximum size of the cache in units.
|
void |
setLowUnits(int cUnits)
Specify the point to which the cache will shrink when it prunes.
|
void |
setUnitCalculator(ConfigurableCacheMap.UnitCalculator calculator)
Set the UnitCalculator for the cache to use.
|
void |
setUnitFactor(int nFactor)
Determine the factor by which the Units, LowUnits and HighUnits properties are adjusted.
|
int |
size()
Returns the number of key-value mappings in this map.
|
String |
toString()
Returns a string representation of this Map.
|
protected void |
touch(Object oKey)
Touch an object to pop it to the top of the LRU
|
protected void |
unregisterKey(Object oKey)
Unregister a key from the SerializationMap.
|
addMapListener, addMapListener, addMapListener, dispatchEvent, dispatchPendingEvent, getMapListenerSupport, hasListeners, removeMapListener, removeMapListener, removeMapListenereraseStore, fromBinary, getBinaryStore, getCacheStatistics, getClassLoader, getInternalKeySet, getKeyMap, instantiateKeyMap, isBinaryMap, setBinaryMap, setClassLoader, toBinaryinstantiateKeyIterator, instantiateKeySet, instantiateValues, isInternalKeySetIteratorMutable, iterateKeysclone, entrySet, equals, getAll, hashCode, keySet, valuesazzert, 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, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, 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, waitfinalize, getClass, notify, notifyAll, wait, wait, waitaddMapListener, addMapListener, addMapListener, removeMapListener, removeMapListener, removeMapListenercompute, computeIfAbsent, computeIfPresent, entrySet, equals, forEach, getOrDefault, hashCode, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll, valuesprotected long m_cMaxUnits
protected long m_cCurUnits
protected long m_cPruneUnits
protected ConfigurableCacheMap.UnitCalculator m_calculator
protected int m_nUnitFactor
protected ConfigurableCacheMap.EvictionApprover m_apprvrEvict
public SerializationCache(BinaryStore store, int cMax)
store - the BinaryStore to use to write the serialized objects tocMax - the maximum number of items to store in the binary storepublic SerializationCache(BinaryStore store, int cMax, ClassLoader loader)
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 deserializationpublic SerializationCache(BinaryStore store, int cMax, boolean fBinaryMap)
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 valuespublic void clear()
clear in interface Mapclear in class AbstractSerializationCachepublic boolean containsKey(Object oKey)
containsKey in interface MapcontainsKey in class AbstractKeySetBasedMappublic boolean containsValue(Object oValue)
containsValue in interface MapcontainsValue in class SerializationMappublic Object get(Object oKey)
get in interface Mapget in class SerializationMapoKey - the key objectpublic boolean isEmpty()
isEmpty in interface MapisEmpty in class AbstractKeySetBasedMappublic Object put(Object oKey, Object oValue)
put in interface CacheMapput in interface Mapput in class AbstractSerializationCacheoKey - key with which the specified value is to be associatedoValue - value to be associated with the specified keypublic void putAll(Map map)
AbstractKeyBasedMap.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.putAll in interface MapputAll in class AbstractSerializationCachemap - the Map containing the key/value pairings to put into this Mappublic Object remove(Object oKey)
remove in interface Mapremove in class AbstractSerializationCacheoKey - key whose mapping is to be removed from the mappublic int size()
size in interface Mapsize in class AbstractKeySetBasedMapprotected boolean removeBlind(Object oKey)
removeBlind in class AbstractSerializationCacheoKey - key whose mapping is to be removed from the mappublic Object put(Object oKey, Object oValue, long cMillis)
CacheMap.put(Object oKey, Object oValue) method allows the caller to specify an expiry (or "time to live") for the cache entry.put in interface CacheMapoKey - 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"; pass CacheMap.EXPIRY_DEFAULT to use the cache's default time-to-live setting; pass CacheMap.EXPIRY_NEVER to indicate that the cache entry should never expire; this milliseconds value is not a date/time value, such as is returned from System.currentTimeMillis()public int getUnits()
Note: It is expected that the return type will be widened to a long in Coherence 4.
getUnits in interface ConfigurableCacheMappublic int getHighUnits()
Note: It is expected that the return type will be widened to a long in Coherence 4.
getHighUnits in interface ConfigurableCacheMappublic void setHighUnits(int cMax)
Note: It is expected that the parameter will be widened to a long in Coherence 4.
setHighUnits in interface ConfigurableCacheMapcMax - the new maximum size of the cache, in unitspublic int getLowUnits()
Note: It is expected that the parameter will be widened to a long in Coherence 4.
getLowUnits in interface ConfigurableCacheMappublic void setLowUnits(int cUnits)
Note: It is expected that the parameter will be widened to a long in Coherence 4.
setLowUnits in interface ConfigurableCacheMapcUnits - the number of units that the cache prunes topublic int getUnitFactor()
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.
getUnitFactor in interface ConfigurableCacheMappublic void setUnitFactor(int nFactor)
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.
setUnitFactor in interface ConfigurableCacheMapnFactor - the units factor; the default is 1public ConfigurableCacheMap.EvictionPolicy getEvictionPolicy()
getEvictionPolicy in interface ConfigurableCacheMappublic void setEvictionPolicy(ConfigurableCacheMap.EvictionPolicy policy)
setEvictionPolicy in interface ConfigurableCacheMappolicy - an EvictionPolicypublic void evict(Object oKey)
evict in interface ConfigurableCacheMapoKey - 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);
}
evictAll in interface ConfigurableCacheMapcolKeys - a collection of keys to evict from the cachepublic void evict()
evict in interface ConfigurableCacheMapevict in class AbstractSerializationCachepublic int getExpiryDelay()
getExpiryDelay in interface ConfigurableCacheMappublic void setExpiryDelay(int cMillis)
setExpiryDelay in interface ConfigurableCacheMapcMillis - the number of milliseconds that cache entries will live, or zero to disable automatic expirypublic long getNextExpiryTime()
getNextExpiryTime in interface ConfigurableCacheMapSafeClock) 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 evictionpublic ConfigurableCacheMap.EvictionApprover getEvictionApprover()
getEvictionApprover in interface ConfigurableCacheMappublic void setEvictionApprover(ConfigurableCacheMap.EvictionApprover approver)
setEvictionApprover in interface ConfigurableCacheMapapprover - the EvictionApproverpublic ConfigurableCacheMap.Entry getCacheEntry(Object oKey)
getCacheEntry in interface ConfigurableCacheMapoKey - the key object to search forpublic ConfigurableCacheMap.UnitCalculator getUnitCalculator()
getUnitCalculator in interface ConfigurableCacheMappublic void setUnitCalculator(ConfigurableCacheMap.UnitCalculator calculator)
setUnitCalculator in interface ConfigurableCacheMapcalculator - a UnitCalculatorpublic void flush()
evict()public String toString()
toString in class SerializationMapprotected void setBinaryStore(BinaryStore store)
setBinaryStore in class SerializationMapstore - the BinaryStore to useprotected long getTouchCounter()
protected LongArray getLruArray()
protected LongArray getExpiryArray()
protected String getDescription()
getDescription in class AbstractSerializationCacheprotected void registerKey(Object oKey, Binary binKey, Binary binValue)
registerKey in class SerializationMapoKey - the key that has been added to the mapbinKey - the binary form of the keybinValue - the binary form of the valueprotected void registerKey(Object oKey, Binary binKey, Binary binValue, int cMillis)
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 entryprotected void touch(Object oKey)
oKey - the key of the object to touchprotected void unregisterKey(Object oKey)
unregisterKey in class SerializationMapoKey - the key that has been removed from the mapprotected void checkSize()
protected void checkExpiry()
public SerializationCache.EntryAttributes instantiateEntryAttributes(SerializationCache.EntryAttributes attrOrig, long ldtExpires, long nTouch, int cUnits)
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 entryprotected Set instantiateEntrySet()
instantiateEntrySet in class AbstractKeySetBasedMap