public class CacheAccess extends java.lang.Object implements ICacheAccess
An instance of this class is tied to a specific cache region. Static methods are provided to get such instances.
Using this class you can retrieve an item, the item's wrapper, and the element's configuration. You can also put an item in the cache, remove an item, and clear a region.
The JCS class is the preferred way to access these methods.
| Modifier and Type | Field and Description |
|---|---|
protected CompositeCache |
cacheControl
The cache that a given instance of this class provides access to.
|
| Constructor and Description |
|---|
CacheAccess(CompositeCache cacheControl)
Constructor for the CacheAccess object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all of the elements from a region.
|
static CacheAccess |
defineRegion(java.lang.String name)
Define a new cache region with the given name.
|
static CacheAccess |
defineRegion(java.lang.String name,
ICompositeCacheAttributes cattr)
Define a new cache region with the specified name and attributes.
|
static CacheAccess |
defineRegion(java.lang.String name,
ICompositeCacheAttributes cattr,
IElementAttributes attr)
Define a new cache region with the specified name and attributes and return a CacheAccess to
it.
|
void |
destroy()
Deprecated.
|
void |
destroy(java.lang.Object name)
Deprecated.
use remove
|
void |
dispose()
Dispose this region.
|
protected static void |
ensureCacheManager()
Helper method which checks to make sure the cacheMgr class field is set, and if not requests
an instance from CacheManagerFactory.
|
int |
freeMemoryElements(int numberToFree)
This instructs the memory cache to remove the numberToFree according to its eviction
policy.
|
java.lang.Object |
get(java.lang.Object name)
Retrieve an object from the cache region this instance provides access to.
|
static CacheAccess |
getAccess(java.lang.String region)
Get a CacheAccess instance for the given region.
|
static CacheAccess |
getAccess(java.lang.String region,
ICompositeCacheAttributes icca)
Get a CacheAccess instance for the given region with the given attributes.
|
ICompositeCacheAttributes |
getCacheAttributes()
Gets the ICompositeCacheAttributes of the cache region.
|
ICacheElement |
getCacheElement(java.lang.Object name)
This method returns the ICacheElement wrapper which provides access to element info and other
attributes.
|
java.util.Map |
getCacheElements(java.util.Set names)
Get multiple elements from the cache based on a set of cache keys.
|
IElementAttributes |
getDefaultElementAttributes()
Retrieves A COPY OF the default element attributes used by this region.
|
IElementAttributes |
getElementAttributes()
Deprecated.
As of release 1.3
|
IElementAttributes |
getElementAttributes(java.lang.Object name)
GetElementAttributes will return an attribute object describing the current attributes
associated with the object name.
|
java.util.HashMap |
getMatching(java.lang.String pattern)
Retrieve matching objects from the cache region this instance provides access to.
|
java.util.Map |
getMatchingCacheElements(java.lang.String pattern)
Get multiple elements from the cache based on a set of cache keys.
|
ICacheStats |
getStatistics()
This returns the ICacheStats object with information on this region and its auxiliaries.
|
java.lang.String |
getStats() |
void |
put(java.lang.Object name,
java.lang.Object obj)
Place a new object in the cache, associated with key name.
|
void |
put(java.lang.Object key,
java.lang.Object val,
IElementAttributes attr)
Constructs a cache element with these attributes, and puts it into the cache.
|
void |
putSafe(java.lang.Object key,
java.lang.Object value)
Place a new object in the cache, associated with key name.
|
void |
remove()
Deprecated.
use clear()
|
void |
remove(java.lang.Object name)
Removes a single item by name.
|
void |
resetElementAttributes(IElementAttributes attr)
Deprecated.
As of release 1.3
|
void |
resetElementAttributes(java.lang.Object name,
IElementAttributes attr)
Reset attributes for a particular element in the cache.
|
void |
setCacheAttributes(ICompositeCacheAttributes cattr)
Sets the ICompositeCacheAttributes of the cache region.
|
void |
setDefaultElementAttributes(IElementAttributes attr)
This method is does not reset the attributes for items already in the cache.
|
protected CompositeCache cacheControl
public CacheAccess(CompositeCache cacheControl)
cacheControl - The cache which the created instance accessespublic static CacheAccess defineRegion(java.lang.String name) throws CacheException
name - Name that will identify the regionCacheExceptionpublic static CacheAccess defineRegion(java.lang.String name, ICompositeCacheAttributes cattr) throws CacheException
name - Name that will identify the regioncattr - CompositeCacheAttributes for the regionCacheExceptionpublic static CacheAccess defineRegion(java.lang.String name, ICompositeCacheAttributes cattr, IElementAttributes attr) throws CacheException
name - Name that will identify the regioncattr - CompositeCacheAttributes for the regionattr - Attributes for the regionCacheExceptionpublic static CacheAccess getAccess(java.lang.String region) throws CacheException
region - Name that identifies the regionCacheExceptionpublic static CacheAccess getAccess(java.lang.String region, ICompositeCacheAttributes icca) throws CacheException
region - Name that identifies the regionicca - CacheExceptionprotected static void ensureCacheManager()
public java.lang.Object get(java.lang.Object name)
get in interface ICacheAccessname - Key the object is stored aspublic java.util.HashMap getMatching(java.lang.String pattern)
getMatching in interface ICacheAccesspattern - - a key pattern for the objects storedpublic ICacheElement getCacheElement(java.lang.Object name)
This returns a reference to the wrapper. Any modifications will be reflected in the cache. No defensive copy is made.
This method is most useful if you want to determine things such as the how long the element has been in the cache.
The last access time in the ElementAttributes should be current.
getCacheElement in interface ICacheAccessname - Key the object is stored aspublic java.util.Map getCacheElements(java.util.Set names)
This method returns the ICacheElement wrapper which provides access to element info and other attributes.
This returns a reference to the wrapper. Any modifications will be reflected in the cache. No defensive copy is made.
This method is most useful if you want to determine things such as the how long the element has been in the cache.
The last access time in the ElementAttributes should be current.
getCacheElements in interface ICacheAccessnames - set of Object cache keyspublic java.util.Map getMatchingCacheElements(java.lang.String pattern)
This method returns the ICacheElement wrapper which provides access to element info and other attributes.
This returns a reference to the wrapper. Any modifications will be reflected in the cache. No defensive copy is made.
This method is most useful if you want to determine things such as the how long the element has been in the cache.
The last access time in the ElementAttributes should be current.
getMatchingCacheElements in interface ICacheAccesspattern - key search patternpublic void putSafe(java.lang.Object key,
java.lang.Object value)
throws CacheException
putSafe in interface ICacheAccesskey - Key object will be stored withvalue - Object to storeCacheException - and ObjectExistsException is thrown if the item is already in the
cache.public void put(java.lang.Object name,
java.lang.Object obj)
throws CacheException
put in interface ICacheAccessname - Key object will be stored withobj - Object to storeCacheExceptionpublic void put(java.lang.Object key,
java.lang.Object val,
IElementAttributes attr)
throws CacheException
If the key or the value is null, and InvalidArgumentException is thrown.
put in interface ICacheAccessCacheExceptionICacheAccess.put(java.lang.Object, java.lang.Object,
org.apache.jcs.engine.behavior.IElementAttributes)public void destroy()
throws CacheException
destroy in interface ICacheAccessCacheExceptionICacheAccess.remove()public void remove()
throws CacheException
remove in interface ICacheAccessCacheExceptionpublic void clear()
throws CacheException
CacheExceptionpublic void destroy(java.lang.Object name)
throws CacheException
destroy in interface ICacheAccessname - Key that specifies object to invalidateCacheExceptionICacheAccess.remove(Object)public void remove(java.lang.Object name)
throws CacheException
remove in interface ICacheAccessname - the name of the item to remove.CacheExceptionpublic void resetElementAttributes(IElementAttributes attr) throws CacheException, InvalidHandleException
NOTE: this method is does not reset the attributes for items already in the cache. It could potentially do this for items in memory, and maybe on disk (which would be slow) but not remote items. Rather than have unpredictable behavior, this method just sets the default attributes.
TODO is should be renamed "setDefaultElementAttributes"
resetElementAttributes in interface ICacheAccessattr - New attributes for this region.CacheExceptionInvalidHandleExceptionsetDefaultElementAttributes(IElementAttributes)public void setDefaultElementAttributes(IElementAttributes attr) throws CacheException
attr - the default attributes.CacheException - if something goes wrong.public void resetElementAttributes(java.lang.Object name,
IElementAttributes attr)
throws CacheException,
InvalidHandleException
resetElementAttributes in interface ICacheAccessname - Key of object to reset attributes forattr - New attributes for the objectCacheExceptionInvalidHandleException - if the item does not exist.public IElementAttributes getElementAttributes() throws CacheException
This was confusing, so I created a new method with a clear name.
getElementAttributes in interface ICacheAccessCacheExceptiongetDefaultElementAttributes()public IElementAttributes getDefaultElementAttributes() throws CacheException
Each time an element is added to the cache without element attributes, the default element attributes are cloned.
CacheExceptionpublic IElementAttributes getElementAttributes(java.lang.Object name) throws CacheException
getElementAttributes in interface ICacheAccessname - Key of object to get attributes forCacheExceptionpublic ICacheStats getStatistics()
This data can be formatted as needed.
public java.lang.String getStats()
public void dispose()
To simply remove all elements from the region use clear().
public ICompositeCacheAttributes getCacheAttributes()
getCacheAttributes in interface ICacheAccesspublic void setCacheAttributes(ICompositeCacheAttributes cattr)
setCacheAttributes in interface ICacheAccesscattr - The new ICompositeCacheAttribute valuepublic int freeMemoryElements(int numberToFree)
throws CacheException
freeMemoryElements in interface ICacheAccessnumberToFree - CacheExceptionCopyright © 2002-2013 Apache Software Foundation. All Rights Reserved.