|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap
com.tangosol.util.SafeHashMap
com.tangosol.net.cache.OldCache
com.tangosol.net.cache.LocalCache
public class LocalCache
A LocalCache implementation that supports the JCache API, CacheLoader and CacheStore objects.
Nested Class Summary | |
---|---|
class |
LocalCache.Entry
A holder for a cached value. |
protected class |
LocalCache.InternalListener
An internal MapListener that listens to this cache and reports changes to the CacheStore. |
protected class |
LocalCache.KeyMask
A 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.OldCache |
---|
OldCache.EntrySet, OldCache.EvictionPolicy, OldCache.KeySet, OldCache.UnitCalculator, OldCache.ValuesCollection |
Field Summary | |
---|---|
static int |
DEFAULT_EXPIRE
By default, the cache entries never expire. |
protected LocalCache.KeyMask |
DEFAULT_KEY_MASK
The default key mask that ignores nothing. |
static int |
DEFAULT_UNITS
By default, the cache size (in units) is infinite. |
Fields inherited from class com.tangosol.net.cache.OldCache |
---|
DEFAULT_FLUSH, DEFAULT_PRUNE, EVICTION_POLICY_EXTERNAL, EVICTION_POLICY_HYBRID, EVICTION_POLICY_LFU, EVICTION_POLICY_LRU, m_calculator, m_cCurUnits, m_cExpiryDelay, m_cFlushDelay, m_cMaxUnits, m_cPruneUnits, m_listenerSupport, m_lNextFlush, m_nCalculatorType, m_nEvictionType, m_policy, m_stats, UNIT_CALCULATOR_BINARY, UNIT_CALCULATOR_EXTERNAL, UNIT_CALCULATOR_FIXED |
Fields inherited from class com.tangosol.util.SafeHashMap |
---|
BIGGEST_MODULO, DEFAULT_GROWTHRATE, DEFAULT_INITIALSIZE, DEFAULT_LOADFACTOR, m_aeBucket, m_cCapacity, m_cEntries, m_colValues, m_flGrowthRate, m_flLoadFactor, m_oIterActive, m_setEntries, m_setKeys, PRIME_MODULO, RESIZING |
Fields inherited from interface com.tangosol.net.cache.CacheMap |
---|
EXPIRY_DEFAULT, EXPIRY_NEVER |
Constructor Summary | |
---|---|
LocalCache()
Construct 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 Summary | |
---|---|
void |
clear()
Removes all mappings from this map. |
Object |
get(Object oKey)
If the specified item is in the cache, return it. |
Map |
getAll(Collection colKeys)
Get all the specified keys, if they are in the cache. |
CacheLoader |
getCacheLoader()
Determine the loader used by this LocalCache, if any. |
protected CacheStore |
getCacheStore()
Determine the store used by this LocalCache, if any. |
SafeHashMap.Entry |
getEntry(Object oKey)
Locate an Entry in the hash map based on its key. |
protected LocalCache.KeyMask |
getKeyMask()
ThreadLocal: Get the current key mask for the current thread. |
protected SafeHashMap.Entry |
instantiateEntry()
Factory method. |
protected MapListener |
instantiateInternalListener()
Factory pattern: Instantiate an internal MapListener to listen to this cache and report changes to the CacheStore. |
protected MapEvent |
instantiateMapEvent(int nId,
Object oKey,
Object oValueOld,
Object oValueNew)
Factory pattern: instantiate a new CacheEvent corresponding to the specified parameters. |
void |
load(Object oKey)
Indicates to the cache that the specified key should be loaded into the cache, if it is not already in the cache. |
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. |
void |
loadAll(Collection colKeys)
Indicates to the cache that the specified keys should be loaded into the cache, if they are not already in the cache. |
Object |
peek(Object oKey)
Checks for a valid entry corresponding to the specified key in the cache, and returns the corresponding value if it is. |
Map |
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. |
Object |
remove(Object oKey)
Removes the mapping for this key from this map if present. |
protected void |
removeExpired(OldCache.Entry entry,
boolean fRemoveInternal)
Remove an entry because it has expired. |
void |
setCacheLoader(CacheLoader loader)
Specify the loader used by this LocalCache. |
protected void |
setKeyMask(LocalCache.KeyMask mask)
ThreadLocal: Set the key mask for the current thread. |
Methods inherited from class com.tangosol.util.SafeHashMap |
---|
clone, cloneEntryList, entrySet, getBucketIndex, getStableBucketArray, grow, isActiveIterator, isEmpty, iteratorActivated, iteratorDeactivated, keySet, removeEntryInternal, values |
Methods inherited from class java.util.AbstractMap |
---|
containsValue, equals, hashCode, putAll |
Methods inherited from interface com.tangosol.net.cache.CacheMap |
---|
put, put |
Methods inherited from interface com.tangosol.util.ObservableMap |
---|
addMapListener, addMapListener, addMapListener, removeMapListener, removeMapListener, removeMapListener |
Methods inherited from interface java.util.Map |
---|
containsKey, containsValue, entrySet, equals, hashCode, isEmpty, keySet, putAll, size, values |
Field Detail |
---|
public static final int DEFAULT_UNITS
public static final int DEFAULT_EXPIRE
protected final LocalCache.KeyMask DEFAULT_KEY_MASK
Constructor Detail |
---|
public LocalCache()
public LocalCache(int cUnits)
cUnits
- the number of units that the cache manager will
cache before pruning the cachepublic LocalCache(int cUnits, int cExpiryMillis)
cUnits
- the number of units that the cache manager will
cache before pruning the cachecExpiryMillis
- the number of milliseconds that each cache entry
lives before being automatically expiredpublic LocalCache(int cUnits, int cExpiryMillis, CacheLoader loader)
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 useMethod Detail |
---|
public void clear()
clear
in interface Map
clear
in class OldCache
public Object remove(Object oKey)
remove
in interface Map
remove
in class OldCache
oKey
- key whose mapping is to be removed from the map
public CacheLoader getCacheLoader()
public void setCacheLoader(CacheLoader loader)
loader
- loader to use, or nullpublic Object get(Object oKey)
get
in interface Map
get
in class OldCache
oKey
- the key to the desired cached item
public SafeHashMap.Entry getEntry(Object oKey)
getEntry
in class OldCache
oKey
- the key to the desired cached Entry
public Map getAll(Collection colKeys)
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;
getAll
in interface CacheMap
colKeys
- a collection of keys that may be in the named cache
public void load(Object oKey)
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.
oKey
- the key to request to be loadedpublic void loadAll()
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.
public void loadAll(Collection colKeys)
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); } } }
colKeys
- a collection of keys to request to be loadedpublic Object peek(Object oKey)
oKey
- the key to "peek" into the cache for
public Map peekAll(Collection colKeys)
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;
colKeys
- a collection of keys to "peek" into the cache for
protected CacheStore getCacheStore()
protected LocalCache.KeyMask getKeyMask()
protected void setKeyMask(LocalCache.KeyMask mask)
mask
- the new key mask, or null to clear the maskprotected void removeExpired(OldCache.Entry entry, boolean fRemoveInternal)
removeExpired
in class OldCache
entry
- the expired cache entryfRemoveInternal
- true if the cache entry still needs to be
removed from the cacheprotected MapEvent instantiateMapEvent(int nId, Object oKey, Object oValueOld, Object oValueNew)
instantiateMapEvent
in class OldCache
protected MapListener instantiateInternalListener()
protected SafeHashMap.Entry instantiateEntry()
instantiateEntry
in class OldCache
|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |