#include <coherence/net/cache/LocalCache.hpp>
Inherits OldCache, and CacheMap.
Public Types | ||||||||||
typedef spec::Handle | Handle | |||||||||
LocalCache Handle definition. | ||||||||||
typedef spec::View | View | |||||||||
LocalCache View definition. | ||||||||||
typedef spec::Holder | Holder | |||||||||
LocalCache Holder definition. | ||||||||||
typedef this_spec::Handle | Handle | |||||||||
CacheMap Handle definition. | ||||||||||
typedef this_spec::View | View | |||||||||
CacheMap View definition. | ||||||||||
typedef this_spec::Holder | Holder | |||||||||
CacheMap Holder definition. | ||||||||||
Public Member Functions | ||||||||||
virtual Object::Holder | remove (Object::View vKey) | |||||||||
Removes the mapping for this key from this map if present. | ||||||||||
virtual void | clear () | |||||||||
Removes all mappings from this map. | ||||||||||
virtual CacheLoader::View | getCacheLoader () const | |||||||||
Determine the loader used by this LocalCache, if any. | ||||||||||
virtual CacheLoader::Handle | getCacheLoader () | |||||||||
Determine the loader used by this LocalCache, if any. | ||||||||||
virtual void | setCacheLoader (CacheLoader::Handle hLoader) | |||||||||
Specify the loader used by this LocalCache. | ||||||||||
virtual Object::Holder | get (Object::View vKey) const | |||||||||
If the specified item is in the cache, return it. | ||||||||||
SafeHashMap::Entry::View | getEntry (Object::View vKey) const | |||||||||
Locate an Entry in the hash map based on its key. | ||||||||||
SafeHashMap::Entry::Handle | getEntry (Object::View vKey) | |||||||||
Locate an Entry in the hash map based on its key. | ||||||||||
virtual Map::View | getAll (Collection::View vColKeys) const | |||||||||
Get all the specified keys, if they are in the cache. | ||||||||||
virtual void | load (Object::View vKey) const | |||||||||
Indicates to the cache that the specified key should be loaded into the cache, if it is not already in the cache. | ||||||||||
virtual void | load (Object::View vKey) | |||||||||
Indicates to the cache that the specified key should be loaded into the cache, if it is not already in the cache. | ||||||||||
virtual 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. | ||||||||||
virtual void | loadAll (Collection::View vColKeys) | |||||||||
Indicates to the cache that the specified keys should be loaded into the cache, if they are not already in the cache. | ||||||||||
virtual void | loadAll (Collection::View vColKeys) const | |||||||||
Indicates to the cache that the specified keys should be loaded into the cache, if they are not already in the cache. | ||||||||||
virtual Object::Holder | peek (Object::View vKey) const | |||||||||
Checks for a valid entry corresponding to the specified key in the cache, and returns the corresponding value if it is. | ||||||||||
virtual Map::Handle | peekAll (Collection::View vColKeys) const | |||||||||
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. | ||||||||||
Static Public Member Functions | ||||||||||
static KeyMask::Handle | getDefaultKeyMask () | |||||||||
Return the default KeyMask for a LocalCache. | ||||||||||
Static Public Attributes | ||||||||||
static const size32_t | max_units | |||||||||
Max number of units this cache can hold. | ||||||||||
static const size32_t | default_units | |||||||||
By default, the cache size (in units) is infinite. | ||||||||||
static const int32_t | never_expire | |||||||||
Never expire entries from the cache. | ||||||||||
static const int32_t | default_expire | |||||||||
By default, the cache entries never expire. | ||||||||||
Protected Member Functions | ||||||||||
LocalCache (int32_t cUnits=default_units, int32_t cExpiryMillis=default_expire, float64_t dflPruneLevel=0.75F, size32_t cInitialBuckets=17, float32_t flLoadFactory=1.0F, float32_t flGrowthRate=3.0F) | ||||||||||
Construct an instance of LocalCache. | ||||||||||
MapListener::Handle | instantiateInternalListener () | |||||||||
Factory pattern: Instantiate an internal MapListener to listen to this cache and report changes to the CacheStore. | ||||||||||
virtual SafeHashMap::Entry::Handle | instantiateEntry (Object::View vKey, Object::Holder ohValue, size32_t nHash) | |||||||||
Factory pattern, initialized with the specified valued.
| ||||||||||
virtual SafeHashMap::Entry::Handle | instantiateEntry (SafeHashMap::Entry::View vEntry) | |||||||||
virtual CacheStore::View | getCacheStore () const | |||||||||
Determine the store used by this LocalCache, if any. | ||||||||||
virtual CacheStore::Handle | getCacheStore () | |||||||||
Determine the store used by this LocalCache, if any. | ||||||||||
virtual KeyMask::View | getKeyMask () const | |||||||||
ThreadLocal: Get the current key mask for the current thread. | ||||||||||
virtual KeyMask::Handle | getKeyMask () | |||||||||
ThreadLocal: Get the current key mask for the current thread. | ||||||||||
virtual void | setKeyMask (KeyMask::Handle hMask) | |||||||||
ThreadLocal: Set the key mask for the current thread. | ||||||||||
virtual void | removeExpired (OldCache::Entry::Handle hEntry, bool fRemoveInternal) | |||||||||
Remove an entry because it has expired. | ||||||||||
virtual MapEvent::Handle | instantiateMapEvent (int32_t nId, Object::View vKey, Object::Holder ohValueOld, Object::Holder ohValueNew) | |||||||||
Factory pattern: instantiate a new CacheEvent corresponding to the specified parameters. | ||||||||||
Classes | ||||||||||
class | Entry | |||||||||
A holder for a cached value. More... | ||||||||||
class | InternalListener | |||||||||
An internal MapListener that listens to this cache and reports changes to the CacheStore. More... | ||||||||||
class | KeyMask | |||||||||
A class that masks certain changes so that they are not reported back to the CacheStore. More... |
LocalCache | ( | int32_t | cUnits = default_units , |
|
int32_t | cExpiryMillis = default_expire , |
|||
float64_t | dflPruneLevel = 0.75F , |
|||
size32_t | cInitialBuckets = 17 , |
|||
float32_t | flLoadFactory = 1.0F , |
|||
float32_t | flGrowthRate = 3.0F | |||
) | [protected] |
Construct an instance of LocalCache.
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 | |
dflPruneLevel | 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 | |
cInitialBuckets | the initial number of hash buckets, 0 < n | |
flLoadFactor | the acceptable load factor before resizing occurs, 0 < n, such that a load factor of 1.0 causes resizing when the number of entries exceeds the number of buckets | |
flGrowthRate | the rate of bucket growth when a resize occurs, 0 < n, such that a growth rate of 1.0 will double the number of buckets: bucketcount = bucketcount * (1 + growthrate) |
MapListener::Handle instantiateInternalListener | ( | ) | [protected] |
Factory pattern: Instantiate an internal MapListener to listen to this cache and report changes to the CacheStore.
virtual Object::Holder remove | ( | Object::View | vKey | ) | [virtual] |
Removes the mapping for this key from this map if present.
oKey | key whose mapping is to be removed from the map |
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 Reimplemented from OldCache.
virtual CacheLoader::View getCacheLoader | ( | ) | const [virtual] |
Determine the loader used by this LocalCache, if any.
virtual CacheLoader::Handle getCacheLoader | ( | ) | [virtual] |
Determine the loader used by this LocalCache, if any.
virtual void setCacheLoader | ( | CacheLoader::Handle | hLoader | ) | [virtual] |
virtual Object::Holder get | ( | Object::View | vKey | ) | const [virtual] |
SafeHashMap::Entry::View getEntry | ( | Object::View | vKey | ) | const [virtual] |
SafeHashMap::Entry::Handle getEntry | ( | Object::View | vKey | ) | [virtual] |
virtual Map::View getAll | ( | Collection::View | vColKeys | ) | const [virtual] |
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;
colKeys | a collection of keys that may be in the named cache |
col
Implements CacheMap.
virtual void load | ( | Object::View | vKey | ) | const [virtual] |
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.
oKey | the key to request to be loaded |
virtual void load | ( | Object::View | vKey | ) | [virtual] |
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.
oKey | the key to request to be loaded |
virtual void loadAll | ( | ) | [virtual] |
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.
virtual void loadAll | ( | Collection::View | vColKeys | ) | [virtual] |
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);
}
}
}
colKeys | a collection of keys to request to be loaded |
virtual void loadAll | ( | Collection::View | vColKeys | ) | const [virtual] |
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);
}
}
}
colKeys | a collection of keys to request to be loaded |
virtual Object::Holder peek | ( | Object::View | vKey | ) | const [virtual] |
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.
oKey | the key to "peek" into the cache for |
virtual Map::Handle peekAll | ( | Collection::View | vColKeys | ) | const [virtual] |
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::Handle hMap = HashMap::create();
for (Iterator::Handle hIter = vColKeys->iterator(); hIter->hasNext(); )
{
Object::View vKey = hIter->next();
Object::Holder ohValue = peek(ohKey);
if (NULL != ohValue || containsKey(vKey))
{
hMap->put(vKey, ohValue);
}
}
return hMap;
vColKeys | a collection of keys to "peek" into the cache for |
static KeyMask::Handle getDefaultKeyMask | ( | ) | [static] |
virtual CacheStore::View getCacheStore | ( | ) | const [protected, virtual] |
Determine the store used by this LocalCache, if any.
virtual CacheStore::Handle getCacheStore | ( | ) | [protected, virtual] |
Determine the store used by this LocalCache, if any.
virtual KeyMask::View getKeyMask | ( | ) | const [protected, virtual] |
ThreadLocal: Get the current key mask for the current thread.
virtual KeyMask::Handle getKeyMask | ( | ) | [protected, virtual] |
ThreadLocal: Get the current key mask for the current thread.
virtual void setKeyMask | ( | KeyMask::Handle | hMask | ) | [protected, virtual] |
ThreadLocal: Set the key mask for the current thread.
mask | the new key mask, or null to clear the mask |
virtual void removeExpired | ( | OldCache::Entry::Handle | hEntry, | |
bool | fRemoveInternal | |||
) | [protected, virtual] |
virtual MapEvent::Handle instantiateMapEvent | ( | int32_t | nId, | |
Object::View | vKey, | |||
Object::Holder | ohValueOld, | |||
Object::Holder | ohValueNew | |||
) | [protected, virtual] |
Factory pattern: instantiate a new CacheEvent corresponding to the specified parameters.
Reimplemented from OldCache.