Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.1.3.0.0)

E47891-01

LocalCache Class Reference

#include <coherence/net/cache/LocalCache.hpp>

Inherits OldCache, and CacheMap.

List of all members.


Detailed Description

A LocalCache implementation that supports CacheLoader and CacheStore objects.

Author:
nsa 2008.08.01

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.

Parameters:
vKey the associated key
ohValue the assocaited value
nHash the associated hash code
Returns:
a new instance of the Entry class (or a subclass thereof)

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...

Constructor & Destructor Documentation

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.

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
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)


Member Function Documentation

MapListener::Handle instantiateInternalListener (  )  [protected]

Factory pattern: Instantiate an internal MapListener to listen to this cache and report changes to the CacheStore.

Returns:
a new MapListener instance

virtual Object::Holder remove ( Object::View  vKey  )  [virtual]

Removes the mapping for this key from this map if present.

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

Reimplemented from OldCache.

virtual CacheLoader::View getCacheLoader (  )  const [virtual]

Determine the loader used by this LocalCache, if any.

Returns:
the loader used by this LocalCache, or null if none

virtual CacheLoader::Handle getCacheLoader (  )  [virtual]

Determine the loader used by this LocalCache, if any.

Returns:
the loader used by this LocalCache, or null if none

virtual void setCacheLoader ( CacheLoader::Handle  hLoader  )  [virtual]

Specify the loader used by this LocalCache.

Parameters:
loader loader to use, or null

virtual Object::Holder get ( Object::View  vKey  )  const [virtual]

If the specified item is in the cache, return it.

Otherwise, load the value for the specified key and return it.

Parameters:
vKey the key to the desired cached item
Returns:
the value corresponding to the specified key, otherwise null

Reimplemented from OldCache.

SafeHashMap::Entry::View getEntry ( Object::View  vKey  )  const [virtual]

Locate 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.

Parameters:
oKey the key to the desired cached Entry
Returns:
the Entry corresponding to the specified key, otherwise null

Reimplemented from OldCache.

SafeHashMap::Entry::Handle getEntry ( Object::View  vKey  )  [virtual]

Locate 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.

Parameters:
oKey the key to the desired cached Entry
Returns:
the Entry corresponding to the specified key, otherwise null

Reimplemented from OldCache.

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;
 

Parameters:
colKeys a collection of keys that may be in the named cache
Returns:
a Map of keys to values for the specified keys passed in 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.

Parameters:
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.

Parameters:
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);
             }
         }
     }
 

Parameters:
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);
             }
         }
     }
 

Parameters:
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.

Parameters:
oKey the key to "peek" into the cache for
Returns:
the value corresponding to the specified key

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;
 

Parameters:
vColKeys a collection of keys to "peek" into the cache for
Returns:
a Map of keys that were found in the cache and their values

static KeyMask::Handle getDefaultKeyMask (  )  [static]

Return the default KeyMask for a LocalCache.

Returns:
the default KeyMask for a LocalCache

virtual CacheStore::View getCacheStore (  )  const [protected, virtual]

Determine the store used by this LocalCache, if any.

Returns:
the CacheStore used by this LocalCache, or null if none

virtual CacheStore::Handle getCacheStore (  )  [protected, virtual]

Determine the store used by this LocalCache, if any.

Returns:
the CacheStore used by this LocalCache, or null if none

virtual KeyMask::View getKeyMask (  )  const [protected, virtual]

ThreadLocal: Get the current key mask for the current thread.

Returns:
the current key mask

virtual KeyMask::Handle getKeyMask (  )  [protected, virtual]

ThreadLocal: Get the current key mask for the current thread.

Returns:
the current key mask

virtual void setKeyMask ( KeyMask::Handle  hMask  )  [protected, virtual]

ThreadLocal: Set the key mask for the current thread.

Parameters:
mask the new key mask, or null to clear the mask

virtual void removeExpired ( OldCache::Entry::Handle  hEntry,
bool  fRemoveInternal 
) [protected, virtual]

Remove an entry because it has expired.

Parameters:
hEntry the expired cache entry
fRemoveInternal true if the cache entry still needs to be removed from the cache

Reimplemented from OldCache.

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.

Returns:
a new instance of the CacheEvent class (or a subclass thereof)

Reimplemented from OldCache.


The documentation for this class was generated from the following file:
Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.