Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


com.tangosol.coherence.weblogic
Class PortalCacheProvider.CacheImpl

java.lang.Object
  extended by com.tangosol.coherence.weblogic.PortalCacheProvider.CacheImpl

All Implemented Interfaces:
com.bea.p13n.cache.Cache, com.bea.p13n.cache.CacheDefaults, com.bea.p13n.cache.CacheStats, com.bea.p13n.cache.ReloadableCache
Direct Known Subclasses:
PortalCacheProvider.ReloadableCacheImpl
Enclosing class:
PortalCacheProvider

protected class PortalCacheProvider.CacheImpl
extends java.lang.Object
implements com.bea.p13n.cache.Cache

Cache implementation that delegates most operations to a Coherence NamedCache.

This implementation does not support the ReloadableCache interface.


Nested Class Summary
protected  class PortalCacheProvider.CacheImpl.EntryInfo
          An EntryInfo contains metadata about a cached Map.Entry.

 

Field Summary
protected  NamedCache m_cache
          The Coherence NamedCache used to implement most cache operations.
protected  LocalCache m_cacheLocal
          The LocalCache of non-serializable objects.
protected  boolean m_fEnabled
          Enabled flag.
protected  ConcurrentMap m_mapEntryInfo
          The Map of EntryInfo objects for this CacheImpl.
protected  java.util.Set m_setLocalClass
          The Set of non-serializable Class objects.
protected  java.lang.String m_sName
          The name of the cache.

 

Fields inherited from interface com.bea.p13n.cache.CacheDefaults
DEFAULT_ENABLED, DEFAULT_MAX_ENTRIES, DEFAULT_TTL, MAX_ENTRIES_MAX, TTL_NEVER_EXPIRE

 

Constructor Summary
protected PortalCacheProvider.CacheImpl(java.lang.String sName, NamedCache cache)
          Create a new CacheImpl.

 

Method Summary
 void clear()
          Remove all entries from the Cache.
protected  boolean compactEntryInfoMap(java.util.Map map, java.lang.Object oKey, PortalCacheProvider.CacheImpl.EntryInfo info)
          Remove the given EntryInfo from the specified Map if it is safe to do so.
 boolean containsKey(java.lang.Object oKey)
          Determine in an entry exists in the Cache.
protected  LocalCache ensureLocalCache()
          Return the LocalCache of non-serializable entries, creating it first if necessary.
 java.util.Set entrySet()
          Returns a Set view of the mappings contained in this cache.
protected  void flush(java.lang.Object oKey)
          Remove the entry with the given key from the EntryInfo Map and from the delegate NamedCache if it is a LocalCache.
protected  void flush(java.lang.Object oKey, boolean fFlushDelegate)
          Remove the entry with the given key from the EntryInfo Map.
 java.lang.Object get(java.lang.Object oKey)
          Return the cached value associated with the given key.
protected  PortalCacheProvider getCacheProvider()
          Return the PortalCacheProvider that created this CacheImpl
protected  java.lang.String getDescription()
          Return a string representation of this CacheImpl's attributes.
protected  ConcurrentMap getEntryInfoMap()
          Return the ConcurrentMap of EntryInfo objects for this CacheImpl.
 long getHitCount()
          Return the current Cache hit count.
 int getHitRate()
          Returns an integer percentage of Cache requests which returned a non-expired value.
protected  LocalCache getLocalCache()
          Return the LocalCache of non-serializable objects.
protected  java.util.Set getLocalClassSet()
          Return the Set of cached non-serializable classes.
 int getMaxEntries()
          Return the maximum number of entries the Cache can store.
 long getMissCount()
          Return the current Cache miss count.
 java.lang.String getName()
          Return the name of the Cache.
protected  NamedCache getNamedCache()
          Return the Coherence NamedCache used to implement most cache operations.
 com.bea.p13n.cache.CacheReloader getReloader(java.lang.Object oKey)
          Return the CacheReloader used for the given key or null if no CacheReloader is currently set.
 long getTtl()
          Get the default time-to-live, in milliseconds, of entries in the Cache.
protected  PortalCacheProvider.CacheImpl.EntryInfo instantiateEntryInfo(boolean fLocal)
          Factory pattern: Create a new EntryInfo.
protected  ConcurrentMap instantiateEntryInfoMap()
          Factory pattern: Create the Map used for concurrency control and to store EntryInfo objects for this CacheImpl.
protected  LocalCache instantiateLocalCache()
          Factory pattern: Create the LocalCache used to cache non-serializable entries
 boolean isEnabled()
          Return true if the Cache is enabled; false otherwise.
 java.util.Set keySet()
          Returns a Set view of the keys contained in this Cache.
 java.lang.Object put(java.lang.Object oKey, java.lang.Object oValue)
          Cache the given value.
 java.lang.Object put(java.lang.Object oKey, java.lang.Object oValue, com.bea.p13n.cache.CacheReloader reloader)
          Cache the given value and specify a CacheReloader used to reload the value when it expires.
 java.lang.Object put(java.lang.Object oKey, java.lang.Object oValue, long cMillis)
          Cache the given value with the specified time-to-live.
 java.lang.Object put(java.lang.Object oKey, java.lang.Object oValue, long cMillis, com.bea.p13n.cache.CacheReloader reloader)
          Cache the given value with a specific time-to-live and specify a CacheReloader used to reload the value when that time-to-live expires.
protected  java.lang.Object put(java.lang.Object oKey, java.lang.Object oValue, long cMillis, PortalCacheProvider.CacheImpl.EntryInfo info, boolean fBlind)
          Cache the given value with the specified time-to-live in the delegate NamedCache.
protected  void release()
          Release all local resources associated with this CacheImpl instance.
 void reload(java.lang.Object oKey)
          Run the CacheReloader associated with the given key to refresh the value in the cache.
 java.lang.Object remove(java.lang.Object oKey)
          Remove an entry from the Cache if it exists.
 void resetStats()
          Reset all Cache statistics.
 void setEnabled(boolean fEnabled)
          Enable or disable the Cache.
 void setMaxEntries(int cEntries)
          Set the maximum number of entries the Cache can store.
 void setReloader(java.lang.Object oKey, com.bea.p13n.cache.CacheReloader reloader)
          Set the CacheReloader to be run when a cached object has expired.
 void setTtl(long cMillis)
          Set the default time-to-live for all entries in the Cache.
 int size()
          Return the size of the Cache.
 java.lang.String toString()
          Return a human readable description of this CacheImpl object.
 com.bea.p13n.cache.CacheReloader unsetReloader(java.lang.Object oKey)
          Remove the CacheReloader used for the given key.

 

Field Detail

m_sName

protected final java.lang.String m_sName
The name of the cache.

m_cache

protected final NamedCache m_cache
The Coherence NamedCache used to implement most cache operations.

m_mapEntryInfo

protected final ConcurrentMap m_mapEntryInfo
The Map of EntryInfo objects for this CacheImpl.

m_setLocalClass

protected final java.util.Set m_setLocalClass
The Set of non-serializable Class objects.

m_cacheLocal

protected LocalCache m_cacheLocal
The LocalCache of non-serializable objects.

m_fEnabled

protected volatile boolean m_fEnabled
Enabled flag.

Constructor Detail

PortalCacheProvider.CacheImpl

protected PortalCacheProvider.CacheImpl(java.lang.String sName,
                                        NamedCache cache)
Create a new CacheImpl.
Parameters:
sName - the name of the Cache; must not be null
cache - the delegate NamedCache; must not be null

Method Detail

getReloader

public com.bea.p13n.cache.CacheReloader getReloader(java.lang.Object oKey)
Return the CacheReloader used for the given key or null if no CacheReloader is currently set.

This method has no effect if the Cache is disabled (null is returned).

Specified by:
getReloader in interface com.bea.p13n.cache.ReloadableCache
Parameters:
oKey - the target key
Returns:
the CacheReloader used to reload the cache value for the given key when the value expires or null if a CacheReloader has not been set for the given key

setReloader

public void setReloader(java.lang.Object oKey,
                        com.bea.p13n.cache.CacheReloader reloader)
Set the CacheReloader to be run when a cached object has expired.

When get() is called with the specified key and the entry has expired, the given CacheReloader is used to reload the object and refresh the Cache. Requests for cached objects without an associated CacheReloader will return null in this situation.

This method has no effect if the Cache is disabled.

Specified by:
setReloader in interface com.bea.p13n.cache.ReloadableCache
Parameters:
oKey - the key to add (or replace) the CacheReloader for
reloader - the new CacheReloader (or null to remove the current CacheReloader)
Throws:
java.lang.IllegalArgumentException - if the Cache does not contain the key

unsetReloader

public com.bea.p13n.cache.CacheReloader unsetReloader(java.lang.Object oKey)
Remove the CacheReloader used for the given key.

This method has no effect if the Cache is disabled (null is returned).

Specified by:
unsetReloader in interface com.bea.p13n.cache.ReloadableCache
Parameters:
oKey - the target key
Returns:
the removed CacheReloader or null if no CacheReloader was currently set

put

public java.lang.Object put(java.lang.Object oKey,
                            java.lang.Object oValue,
                            com.bea.p13n.cache.CacheReloader reloader)
Cache the given value and specify a CacheReloader used to reload the value when it expires.

Neither the key nor the value may be null. The reloader may be null (in which case no CacheReloader is used and the value will expire in the "normal" way.)

Specified by:
put in interface com.bea.p13n.cache.ReloadableCache
Parameters:
oKey - key with which the specified value is to be cached; must not be null
oValue - value to cache; must not be null
reloader - the CacheReloader to associate with the given key
Returns:
the previously cached value for the given key

put

public java.lang.Object put(java.lang.Object oKey,
                            java.lang.Object oValue,
                            long cMillis,
                            com.bea.p13n.cache.CacheReloader reloader)
Cache the given value with a specific time-to-live and specify a CacheReloader used to reload the value when that time-to-live expires.

Neither the key nor the value may be null. The reloader may be null (in which case no CacheReloader is used and the value will expire in the "normal" way.)

Specified by:
put in interface com.bea.p13n.cache.ReloadableCache
Parameters:
oKey - key with which the specified value is to be cached; must not be null
oValue - value to cache; must not be null
cMillis - the time-to-live, in milliseconds, of the cached object; this TTL overrides the default TTL for the Cache, and applies only to the given key
reloader - the CacheReloader to associate with the given key
Returns:
the previously cached value for the given key

reload

public void reload(java.lang.Object oKey)
Run the CacheReloader associated with the given key to refresh the value in the cache. This method blocks until the object is reloaded.

This method has no effect if the Cache is disabled.

Specified by:
reload in interface com.bea.p13n.cache.ReloadableCache
Parameters:
oKey - the target key

put

public java.lang.Object put(java.lang.Object oKey,
                            java.lang.Object oValue)
Cache the given value.

This method has no effect if the Cache is disabled (null is returned).

Specified by:
put in interface com.bea.p13n.cache.Cache
Parameters:
oKey - the key of the entry to create; must not be null
oValue - the value to associate with the key; must not be null
Returns:
the previous value associated with the given key

put

public java.lang.Object put(java.lang.Object oKey,
                            java.lang.Object oValue,
                            long cMillis)
Cache the given value with the specified time-to-live.

This method has no effect if the Cache is disabled (null is returned).

Specified by:
put in interface com.bea.p13n.cache.Cache
Parameters:
oKey - the key of the entry to create; must not be null
oValue - the value to associate with the key; must not be null
cMillis - the time-to-live, in milliseconds, of the cached object; this TTL overrides the default TTL for the Cache, and applies only to the given key
Returns:
the previous value associated with the given key

get

public java.lang.Object get(java.lang.Object oKey)
Return the cached value associated with the given key.

This method has no effect if the Cache is disabled (null is returned).

Specified by:
get in interface com.bea.p13n.cache.Cache
Parameters:
oKey - the target key; must not be null
Returns:
the cache value associated with the given key or null if no such mapping exists or has expired

clear

public void clear()
Remove all entries from the Cache.

This method has no effect if the Cache is disabled (null is returned).

Specified by:
clear in interface com.bea.p13n.cache.Cache

remove

public java.lang.Object remove(java.lang.Object oKey)
Remove an entry from the Cache if it exists.

This method has no effect if the Cache is disabled (null is returned).

Specified by:
remove in interface com.bea.p13n.cache.Cache
Parameters:
oKey - the key of the entry to remove; must not be null
Returns:
the value of the entry that was removed or null if no such mapping exists

size

public int size()
Return the size of the Cache.

If the Cache is disabled, -1 is returned.

Specified by:
size in interface com.bea.p13n.cache.Cache
Returns:
the number of entries that this Cache contains

keySet

public java.util.Set keySet()
Returns a Set view of the keys contained in this Cache. The Set is backed by the Cache, so changes to the Cache are reflected in the Set, and vice-versa.

If the Cache is disabled, an empty immutable Set is returned.

Specified by:
keySet in interface com.bea.p13n.cache.Cache
Returns:
a set view of the keys contained in this map.

entrySet

public java.util.Set entrySet()
Returns a Set view of the mappings contained in this cache. Each element in the returned Set is a Map.Entry. The Set is backed by the Cache, so changes to the Cache are reflected in the Set, and vice-versa.

If the Cache is disabled, an empty immutable Set is returned.

Specified by:
entrySet in interface com.bea.p13n.cache.Cache
Returns:
a Set view of the mappings contained in this Cache.

containsKey

public boolean containsKey(java.lang.Object oKey)
Determine in an entry exists in the Cache.

If the Cache is disabled, false is returned.

Specified by:
containsKey in interface com.bea.p13n.cache.Cache
Parameters:
oKey - the target key; must not be null
Returns:
true if an object is currently associated with the given key; false otherwise

getTtl

public long getTtl()
Get the default time-to-live, in milliseconds, of entries in the Cache. Unless specified for each entry individually, the time-to-live is set upon creation of the Cache and applies to all entries in the Cache.

This method is unsupported (returns -1).

Specified by:
getTtl in interface com.bea.p13n.cache.Cache
Returns:
the default time-to-live, in milliseconds

setTtl

public void setTtl(long cMillis)
Set the default time-to-live for all entries in the Cache. Note that using a value of TTL_NEVER_EXPIRE means entries will never expire.

This method is unsupported and has no effect.

Specified by:
setTtl in interface com.bea.p13n.cache.Cache
Parameters:
cMillis - the new default time-to-live in milliseconds

getMaxEntries

public int getMaxEntries()
Return the maximum number of entries the Cache can store.

This method is unsupported (returns -1).

Specified by:
getMaxEntries in interface com.bea.p13n.cache.Cache
Returns:
the maximum number of entries

setMaxEntries

public void setMaxEntries(int cEntries)
Set the maximum number of entries the Cache can store.

This method is unsupported and has no effect.

Specified by:
setMaxEntries in interface com.bea.p13n.cache.Cache
Parameters:
cEntries - the new maximum number of entries

getName

public java.lang.String getName()
Return the name of the Cache. Each Cache has a unique name, and is referenced by that name. The CacheFactory maintains a collection of Cache instances, keyed by their names.
Specified by:
getName in interface com.bea.p13n.cache.Cache
Returns:
the unique name of the Cache

isEnabled

public boolean isEnabled()
Return true if the Cache is enabled; false otherwise.

See the JavaDoc for the various Cache methods for a description of their behavior when the Cache is disabled.

Specified by:
isEnabled in interface com.bea.p13n.cache.Cache
Returns:
true if the Cache is enabled; false otherwise

setEnabled

public void setEnabled(boolean fEnabled)
Enable or disable the Cache.

See the JavaDoc for the various Cache methods for a description of their behavior when the Cache is disabled.

Specified by:
setEnabled in interface com.bea.p13n.cache.Cache
Parameters:
fEnabled - true to enable the Cache; false to disable it

resetStats

public void resetStats()
Reset all Cache statistics.

This method is unsupported and has no effect.

Specified by:
resetStats in interface com.bea.p13n.cache.CacheStats

getHitCount

public long getHitCount()
Return the current Cache hit count.

This method is unsupported (returns -1).

Specified by:
getHitCount in interface com.bea.p13n.cache.CacheStats
Returns:
the current number of hits

getMissCount

public long getMissCount()
Return the current Cache miss count.

This method is unsupported (returns -1).

Specified by:
getMissCount in interface com.bea.p13n.cache.CacheStats
Returns:
the current number of misses

getHitRate

public int getHitRate()
Returns an integer percentage of Cache requests which returned a non-expired value.

This method is unsupported (returns -1).

Specified by:
getHitRate in interface com.bea.p13n.cache.CacheStats
Returns:
the current hit rate

toString

public java.lang.String toString()
Return a human readable description of this CacheImpl object.
Specified by:
toString in interface com.bea.p13n.cache.Cache
Returns:
a human readable description of this CacheImpl object

release

protected void release()
Release all local resources associated with this CacheImpl instance.

Releasing a CacheImpl reference makes it no longer usable; any attempt to use the reference may result in an exception.


put

protected java.lang.Object put(java.lang.Object oKey,
                               java.lang.Object oValue,
                               long cMillis,
                               PortalCacheProvider.CacheImpl.EntryInfo info,
                               boolean fBlind)
Cache the given value with the specified time-to-live in the delegate NamedCache.

If a serialization error occurs during the put() operation, the given value will be cached in the LocalCache returned by ensureLocalCache() and a message will be logged.

This method is not thread safe.

Parameters:
oKey - the key of the entry to create; must not be null
oValue - the value to associate with the key; must not be null
cMillis - the time-to-live, in milliseconds, of the cached object; this TTL overrides the default TTL for the Cache, and applies only to the given key
info - the EntryInfo for the given key
fBlind - if true, a "blind" put() will be performed and null will be returned
Returns:
the previous value associated with the given key

flush

protected void flush(java.lang.Object oKey)
Remove the entry with the given key from the EntryInfo Map and from the delegate NamedCache if it is a LocalCache. If the key is null, the EntryInfo Map is cleared as is the delegate NamedCache if it is a LocalCache.
Parameters:
oKey - the optional key to flush; if null, the entire Cache will be flushed

flush

protected void flush(java.lang.Object oKey,
                     boolean fFlushDelegate)
Remove the entry with the given key from the EntryInfo Map. If the key is null, the EntryInfo Map is cleared.

If the fFlushDelegate parameter is true, the remove or clear operation is also performed on the delegate NamedCache.

Parameters:
oKey - the optional key to flush; if null, the entire Cache will be flushed
fFlushDelegate - if true, the remove or clear operation will also be performed on the delegate named cache

compactEntryInfoMap

protected boolean compactEntryInfoMap(java.util.Map map,
                                      java.lang.Object oKey,
                                      PortalCacheProvider.CacheImpl.EntryInfo info)
Remove the given EntryInfo from the specified Map if it is safe to do so.

This method is not thread safe.

Parameters:
map - the Map that contains the EntryInfo
oKey - the key used to store the EntryInfo in the given Map
info - the candidate EntryInfo
Returns:
true if the EntryInfo was removed from the Map; false otherwise

getDescription

protected java.lang.String getDescription()
Return a string representation of this CacheImpl's attributes.
Returns:
a string representation of this CacheImpl's attributes

instantiateEntryInfoMap

protected ConcurrentMap instantiateEntryInfoMap()
Factory pattern: Create the Map used for concurrency control and to store EntryInfo objects for this CacheImpl.
Returns:
a new ConcurrentMap instance

instantiateLocalCache

protected LocalCache instantiateLocalCache()
Factory pattern: Create the LocalCache used to cache non-serializable entries
Returns:
a new LocalCache instance

ensureLocalCache

protected LocalCache ensureLocalCache()
Return the LocalCache of non-serializable entries, creating it first if necessary.
Returns:
the LocalCache (never null) that this CacheImpl uses to cache non-serializable entries

instantiateEntryInfo

protected PortalCacheProvider.CacheImpl.EntryInfo instantiateEntryInfo(boolean fLocal)
Factory pattern: Create a new EntryInfo.
Parameters:
fLocal - if true, the corresponding Map.Entry is stored in the local Map
Returns:
a new EntryInfo

getCacheProvider

protected PortalCacheProvider getCacheProvider()
Return the PortalCacheProvider that created this CacheImpl
Returns:
the PortalCacheProvider

getNamedCache

protected NamedCache getNamedCache()
Return the Coherence NamedCache used to implement most cache operations.
Returns:
the delegate NamedCache (never null)

getEntryInfoMap

protected ConcurrentMap getEntryInfoMap()
Return the ConcurrentMap of EntryInfo objects for this CacheImpl.
Returns:
the ConcurrentMap object (never null) that this CacheImpl uses to control concurrency and to store EntryInfo objects;

getLocalClassSet

protected java.util.Set getLocalClassSet()
Return the Set of cached non-serializable classes.
Returns:
the Map object (never null) that this CacheImpl uses to cache non-serializable classes

getLocalCache

protected LocalCache getLocalCache()
Return the LocalCache of non-serializable objects.
Returns:
the LocalCache that this CacheImpl uses to cache non-serializable objects

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.