|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.jcs.access.CacheAccess<K,V>
public class CacheAccess<K extends Serializable,V extends Serializable>
This class provides an interface for all types of access to the cache.
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.
| Field Summary | |
|---|---|
protected CompositeCache<K,V> |
cacheControl
The cache that a given instance of this class provides access to. |
| Constructor Summary | |
|---|---|
CacheAccess(CompositeCache<K,V> cacheControl)
Constructor for the CacheAccess object. |
|
| Method Summary | ||
|---|---|---|
void |
clear()
Removes all of the elements from a region. |
|
static
|
defineRegion(String name)
Define a new cache region with the given name. |
|
static
|
defineRegion(String name,
ICompositeCacheAttributes cattr)
Define a new cache region with the specified name and attributes. |
|
static
|
defineRegion(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(K name)
Deprecated. use remove |
|
void |
dispose()
Dispose this region. |
|
int |
freeMemoryElements(int numberToFree)
This instructs the memory cache to remove the numberToFree according to its eviction policy. |
|
V |
get(K name)
Retrieve an object from the cache region this instance provides access to. |
|
static
|
getAccess(String region)
Get a CacheAccess instance for the given region. |
|
static
|
getAccess(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<K,V> |
getCacheElement(K name)
This method returns the ICacheElement |
|
Map<K,ICacheElement<K,V>> |
getCacheElements(Set<K> names)
Get multiple elements from the cache based on a set of cache keys. |
|
protected static CompositeCacheManager |
getCacheManager()
Helper method which checks to make sure the cacheMgr class field is set, and if not requests an instance from CacheManagerFactory. |
|
IElementAttributes |
getDefaultElementAttributes()
Retrieves A COPY OF the default element attributes used by this region. |
|
IElementAttributes |
getElementAttributes()
Deprecated. As of release 1.3 |
|
IElementAttributes |
getElementAttributes(K name)
GetElementAttributes will return an attribute object describing the current attributes associated with the object name. |
|
Map<K,V> |
getMatching(String pattern)
Retrieve matching objects from the cache region this instance provides access to. |
|
Map<K,ICacheElement<K,V>> |
getMatchingCacheElements(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. |
|
String |
getStats()
|
|
void |
put(K name,
V obj)
Place a new object in the cache, associated with key name. |
|
void |
put(K key,
V val,
IElementAttributes attr)
Constructs a cache element with these attributes, and puts it into the cache. |
|
void |
putSafe(K key,
V value)
Place a new object in the cache, associated with key name. |
|
void |
remove()
Deprecated. use clear() |
|
void |
remove(K name)
Removes a single item by name. |
|
void |
resetElementAttributes(IElementAttributes attr)
Deprecated. As of release 1.3 |
|
void |
resetElementAttributes(K 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. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected CompositeCache<K extends Serializable,V extends Serializable> cacheControl
| Constructor Detail |
|---|
public CacheAccess(CompositeCache<K,V> cacheControl)
cacheControl - The cache which the created instance accesses| Method Detail |
|---|
public static <K extends Serializable,V extends Serializable> CacheAccess<K,V> defineRegion(String name)
throws CacheException
name - Name that will identify the region
CacheException
public static <K extends Serializable,V extends Serializable> CacheAccess<K,V> defineRegion(String name,
ICompositeCacheAttributes cattr)
throws CacheException
name - Name that will identify the regioncattr - CompositeCacheAttributes for the region
CacheException
public static <K extends Serializable,V extends Serializable> CacheAccess<K,V> defineRegion(String name,
ICompositeCacheAttributes cattr,
IElementAttributes attr)
throws CacheException
name - Name that will identify the regioncattr - CompositeCacheAttributes for the regionattr - Attributes for the region
CacheException
public static <K extends Serializable,V extends Serializable> CacheAccess<K,V> getAccess(String region)
throws CacheException
region - Name that identifies the region
CacheException
public static <K extends Serializable,V extends Serializable> CacheAccess<K,V> getAccess(String region,
ICompositeCacheAttributes icca)
throws CacheException
region - Name that identifies the regionicca -
CacheException
protected static CompositeCacheManager getCacheManager()
throws CacheException
CacheException - if the configuration cannot be loadedpublic V get(K name)
get in interface ICacheAccess<K extends Serializable,V extends Serializable>name - Key the object is stored as
public Map<K,V> getMatching(String pattern)
getMatching in interface ICacheAccess<K extends Serializable,V extends Serializable>pattern - - a key pattern for the objects stored
public ICacheElement<K,V> getCacheElement(K 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 ICacheAccess<K extends Serializable,V extends Serializable>name - Key the Serializable is stored as
public Map<K,ICacheElement<K,V>> getCacheElements(Set<K> names)
This method returns the ICacheElement
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 ICacheAccess<K extends Serializable,V extends Serializable>
names - set of Serializable cache keys
public Map<K,ICacheElement<K,V>> getMatchingCacheElements(String pattern)
This method returns the ICacheElement
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 ICacheAccess<K extends Serializable,V extends Serializable>
pattern - key search pattern
public void putSafe(K key,
V value)
throws CacheException
putSafe in interface ICacheAccess<K extends Serializable,V extends Serializable>key - Key object will be stored withvalue - Object to store
CacheException - and ObjectExistsException is thrown if the item is already in the
cache.
public void put(K name,
V obj)
throws CacheException
put in interface ICacheAccess<K extends Serializable,V extends Serializable>name - Key object will be stored withobj - Object to store
CacheException
public void put(K key,
V val,
IElementAttributes attr)
throws CacheException
If the key or the value is null, and InvalidArgumentException is thrown.
put in interface ICacheAccess<K extends Serializable,V extends Serializable>CacheExceptionorg.apache.jcs.access.behavior.ICacheAccess#put(java.lang.Object, java.lang.Object,
org.apache.jcs.engine.behavior.IElementAttributes)
@Deprecated
public void destroy()
throws CacheException
CacheException
@Deprecated
public void remove()
throws CacheException
remove in interface ICacheAccess<K extends Serializable,V extends Serializable>CacheException
public void clear()
throws CacheException
CacheException
@Deprecated
public void destroy(K name)
throws CacheException
name - Key that specifies object to invalidate
CacheException
public void remove(K name)
throws CacheException
remove in interface ICacheAccess<K extends Serializable,V extends Serializable>name - the name of the item to remove.
CacheException
@Deprecated
public 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 ICacheAccess<K extends Serializable,V extends Serializable>attr - New attributes for this region.
CacheException
InvalidHandleExceptionsetDefaultElementAttributes(IElementAttributes)
public void setDefaultElementAttributes(IElementAttributes attr)
throws CacheException
attr - the default attributes.
CacheException - if something goes wrong.
public void resetElementAttributes(K name,
IElementAttributes attr)
throws CacheException,
InvalidHandleException
resetElementAttributes in interface ICacheAccess<K extends Serializable,V extends Serializable>name - Key of object to reset attributes forattr - New attributes for the object
CacheException
InvalidHandleException - if the item does not exist.
@Deprecated
public IElementAttributes getElementAttributes()
throws CacheException
This was confusing, so I created a new method with a clear name.
getElementAttributes in interface ICacheAccess<K extends Serializable,V extends Serializable>CacheExceptiongetDefaultElementAttributes()
public IElementAttributes getDefaultElementAttributes()
throws CacheException
Each time an element is added to the cache without element attributes, the default element attributes are cloned.
CacheException
public IElementAttributes getElementAttributes(K name)
throws CacheException
getElementAttributes in interface ICacheAccess<K extends Serializable,V extends Serializable>name - Key of object to get attributes for
CacheExceptionpublic ICacheStats getStatistics()
This data can be formatted as needed.
public String getStats()
public void dispose()
To simply remove all elements from the region use clear().
public ICompositeCacheAttributes getCacheAttributes()
getCacheAttributes in interface ICacheAccess<K extends Serializable,V extends Serializable>public void setCacheAttributes(ICompositeCacheAttributes cattr)
setCacheAttributes in interface ICacheAccess<K extends Serializable,V extends Serializable>cattr - The new ICompositeCacheAttribute value
public int freeMemoryElements(int numberToFree)
throws CacheException
freeMemoryElements in interface ICacheAccess<K extends Serializable,V extends Serializable>numberToFree -
CacheException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||