Class LocalCache
- All Implemented Interfaces:
- CacheMap,- ConfigurableCacheMap,- ObservableMap,- Serializable,- Cloneable,- Map
- Since:
- Coherence 2.2
- Author:
- cp 2003.05.30
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionclassA holder for a cached value.protected classAn internal MapListener that listens to this cache and reports changes to the CacheStore.protected classA class that masks certain changes so that they are not reported back to the CacheStore.Nested classes/interfaces inherited from class com.tangosol.net.cache.OldCacheOldCache.EntrySet, OldCache.EvictionPolicy, OldCache.InternalEvictionPolicy, OldCache.InternalUnitCalculator, OldCache.KeySet, OldCache.UnitCalculator, OldCache.ValuesCollectionNested classes/interfaces inherited from class java.util.AbstractMapAbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> Nested classes/interfaces inherited from interface com.tangosol.net.cache.ConfigurableCacheMapConfigurableCacheMap.EvictionApprover
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intBy default, the cache entries never expire.protected final LocalCache.KeyMaskThe default key mask that ignores nothing.static final intBy default, the cache size (in units) is infinite.Fields inherited from class com.tangosol.net.cache.OldCacheDEFAULT_FLUSH, DEFAULT_PRUNE, EVICTION_POLICY_EXTERNAL, EVICTION_POLICY_HYBRID, EVICTION_POLICY_LFU, EVICTION_POLICY_LRU, INSTANCE_BINARY, INSTANCE_FIXED, INSTANCE_HYBRID, INSTANCE_LFU, INSTANCE_LRU, m_apprvrEvict, m_arrayExpiry, m_calculator, m_cAvgTouch, m_cCurUnits, m_cExpiryDelay, m_cMaxUnits, m_cPruneUnits, m_dflPruneLevel, m_fIncrementalEvict, m_fOptimizeGetTime, m_iterEvict, m_listenerSupport, m_lLastPrune, m_lNextFlush, m_nCalculatorType, m_nEvictionType, m_nUnitFactor, m_policy, m_stats, UNIT_CALCULATOR_BINARY, UNIT_CALCULATOR_EXTERNAL, UNIT_CALCULATOR_FIXEDFields inherited from class com.tangosol.util.SafeHashMapBIGGEST_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.CacheMapEXPIRY_DEFAULT, EXPIRY_NEVER
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct the cache manager.LocalCache(int cUnits) Construct the cache manager.LocalCache(int cUnits, int cExpiryMillis) Construct the cache manager.LocalCache(int cUnits, int cExpiryMillis, CacheLoader loader) Construct the cache manager.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclear()Removes all mappings from this map.If the specified item is in the cache, return it.getAll(Collection colKeys) Get all the specified keys, if they are in the cache.Determine the loader used by this LocalCache, if any.protected CacheStoreDetermine the store used by this LocalCache, if any.Locate an Entry in the hash map based on its key.protected LocalCache.KeyMaskThreadLocal: Get the current key mask for the current thread.protected SafeHashMap.EntryFactory method.protected MapListenerFactory pattern: Instantiate an internal MapListener to listen to this cache and report changes to the CacheStore.protected MapEventinstantiateMapEvent(int nId, Object oKey, Object oValueOld, Object oValueNew) Factory pattern: instantiate a new CacheEvent corresponding to the specified parameters.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.Removes the mapping for this key from this map if present.protected booleanremoveEvicted(OldCache.Entry entry) Remove an entry (if it is eligible for eviction) because it has expired.voidsetCacheLoader(CacheLoader loader) Specify the loader used by this LocalCache.protected voidsetKeyMask(LocalCache.KeyMask mask) ThreadLocal: Set the key mask for the current thread.Methods inherited from class com.tangosol.net.cache.OldCacheaddMapListener, addMapListener, addMapListener, adjustUnits, checkFlush, configureEviction, configureUnitCalculator, containsKey, dispatchEvent, evict, evict, evictAll, getCacheEntry, getCacheHits, getCacheMisses, getCacheStatistics, getCurrentTimeMillis, getEntryInternal, getEvictionApprover, getEvictionPolicy, getEvictionType, getExpiryDelay, getFlushTime, getHighUnits, getHitProbability, getLowUnits, getMapListenerSupport, getNextExpiryTime, getUnitCalculator, getUnitCalculatorType, getUnitFactor, getUnits, hasListeners, instantiateEntrySet, instantiateKeySet, instantiateValuesCollection, isEmpty, isIncrementalEviction, prune, put, put, removeExpired, removeIfExpired, removeMapListener, removeMapListener, removeMapListener, resetHitStatistics, setEvictionApprover, setEvictionPolicy, setEvictionType, setExpiryDelay, setFlushTime, setHighUnits, setIncrementalEviction, setLowUnits, setOptimizeGetTime, setUnitCalculator, setUnitCalculatorType, setUnitFactor, size, toExternalUnits, toInternalUnits, toString, tryEvictMethods inherited from class com.tangosol.util.SafeHashMapclone, cloneEntryList, compute, computeIfAbsent, computeIfPresent, entrySet, getBucketIndex, getStableBucketArray, grow, instantiateEntry, isActiveIterator, iteratorActivated, iteratorDeactivated, keySet, merge, putIfAbsent, remove, removeEntryInternal, replace, replace, replaceAll, valuesMethods inherited from class java.util.AbstractMapcontainsValue, equals, hashCode, putAllMethods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, size, valuesMethods inherited from interface com.tangosol.util.ObservableMapaddMapListener, addMapListener, addMapListener, removeMapListener, removeMapListener, removeMapListener
- 
Field Details- 
DEFAULT_UNITSpublic static final int DEFAULT_UNITSBy default, the cache size (in units) is infinite.- See Also:
 
- 
DEFAULT_EXPIREpublic static final int DEFAULT_EXPIREBy default, the cache entries never expire.- See Also:
 
- 
DEFAULT_KEY_MASKThe default key mask that ignores nothing.
 
- 
- 
Constructor Details- 
LocalCachepublic LocalCache()Construct the cache manager.
- 
LocalCachepublic LocalCache(int cUnits) Construct the cache manager.- Parameters:
- cUnits- the number of units that the cache manager will cache before pruning the cache
 
- 
LocalCachepublic LocalCache(int cUnits, int cExpiryMillis) Construct the cache manager.- Parameters:
- cUnits- the number of units that the cache manager will cache before pruning the cache
- cExpiryMillis- the number of milliseconds that each cache entry lives before being automatically expired
 
- 
LocalCacheConstruct the cache manager.- Parameters:
- cUnits- the number of units that the cache manager will cache before pruning the cache
- cExpiryMillis- the number of milliseconds that each cache entry lives before being automatically expired
- loader- the CacheLoader or CacheStore to use
 
 
- 
- 
Method Details- 
clearpublic void clear()Removes all mappings from this map.
- 
removeRemoves the mapping for this key from this map if present.- Specified by:
- removein interface- Map
- Overrides:
- removein class- OldCache
- 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
 
- 
getCacheLoaderDetermine the loader used by this LocalCache, if any.- Returns:
- the loader used by this LocalCache, or null if none
 
- 
setCacheLoaderSpecify the loader used by this LocalCache.- Parameters:
- loader- loader to use, or null
 
- 
getIf the specified item is in the cache, return it. Otherwise, load the value for the specified key and return it.
- 
getEntryLocate 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.
- 
getAllGet 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;
- 
loadIndicates 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
 
- 
loadAllpublic 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. 
- 
loadAllIndicates 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
 
- 
peekChecks 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
 
- 
peekAllChecks 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
 
- 
getCacheStoreDetermine the store used by this LocalCache, if any.- Returns:
- the CacheStore used by this LocalCache, or null if none
 
- 
getKeyMaskThreadLocal: Get the current key mask for the current thread.- Returns:
- the current key mask
 
- 
setKeyMaskThreadLocal: Set the key mask for the current thread.- Parameters:
- mask- the new key mask, or null to clear the mask
 
- 
removeEvictedRemove an entry (if it is eligible for eviction) because it has expired.- Overrides:
- removeEvictedin class- OldCache
- Parameters:
- entry- the expired cache entry
- Returns:
- true iff the entry was removed
 
- 
instantiateMapEventFactory pattern: instantiate a new CacheEvent corresponding to the specified parameters.- Overrides:
- instantiateMapEventin class- OldCache
- Parameters:
- nId- the event Id
- oKey- the key
- oValueOld- the old value
- oValueNew- the new value
- Returns:
- a new instance of the CacheEvent class (or a subclass thereof)
 
- 
instantiateInternalListenerFactory pattern: Instantiate an internal MapListener to listen to this cache and report changes to the CacheStore.- Returns:
- a new MapListener instance
 
- 
instantiateEntryFactory method. This method exists to allow the OldCache class to be easily inherited from by allowing the Entry class to be easily sub-classed.- Overrides:
- instantiateEntryin class- OldCache
- Returns:
- an instance of Entry that holds the passed cache value
 
 
-