Package org.apache.commons.jcs3.access
Class AbstractCacheAccess<K,V>
java.lang.Object
org.apache.commons.jcs3.access.AbstractCacheAccess<K,V>
- All Implemented Interfaces:
ICacheAccessManagement
- Direct Known Subclasses:
CacheAccess
,GroupCacheAccess
This class provides the common methods 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.
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractCacheAccess
(CompositeCache<K, V> cacheControl) Constructor for the CacheAccess object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all of the elements from a region.void
dispose()
Dispose this region.int
freeMemoryElements
(int numberToFree) This instructs the memory cache to remove the numberToFree according to its eviction policy.Gets the ICompositeCacheAttributes of the cache region.Retrieves A COPY OF the default element attributes used by this region.This returns the ICacheStats object with information on this region and its auxiliaries.getStats()
void
Sets the ICompositeCacheAttributes of the cache region.void
This method is does not reset the attributes for items already in the cache.
-
Constructor Details
-
AbstractCacheAccess
Constructor for the CacheAccess object.- Parameters:
cacheControl
- The cache which the created instance accesses
-
-
Method Details
-
clear
Removes all of the elements from a region.- Specified by:
clear
in interfaceICacheAccessManagement
- Throws:
CacheException
-
setDefaultElementAttributes
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. Items subsequently put into the cache will use these defaults if they do not specify specific attributes.- Specified by:
setDefaultElementAttributes
in interfaceICacheAccessManagement
- Parameters:
attr
- the default attributes.- Throws:
CacheException
- if something goes wrong.
-
getDefaultElementAttributes
Retrieves A COPY OF the default element attributes used by this region. This does not provide a reference to the element attributes.Each time an element is added to the cache without element attributes, the default element attributes are cloned.
- Specified by:
getDefaultElementAttributes
in interfaceICacheAccessManagement
- Returns:
- the default element attributes used by this region.
- Throws:
CacheException
-
getStatistics
This returns the ICacheStats object with information on this region and its auxiliaries.This data can be formatted as needed.
- Specified by:
getStatistics
in interfaceICacheAccessManagement
- Returns:
- ICacheStats
-
getStats
- Specified by:
getStats
in interfaceICacheAccessManagement
- Returns:
- A String version of the stats.
-
dispose
Dispose this region. Flushes objects to and closes auxiliary caches. This is a shutdown command!To simply remove all elements from the region use clear().
- Specified by:
dispose
in interfaceICacheAccessManagement
-
getCacheAttributes
Gets the ICompositeCacheAttributes of the cache region.- Specified by:
getCacheAttributes
in interfaceICacheAccessManagement
- Returns:
- ICompositeCacheAttributes, the controllers config info, defined in the top section of a region definition.
-
setCacheAttributes
Sets the ICompositeCacheAttributes of the cache region.- Specified by:
setCacheAttributes
in interfaceICacheAccessManagement
- Parameters:
cattr
- The new ICompositeCacheAttribute value
-
freeMemoryElements
This instructs the memory cache to remove the numberToFree according to its eviction policy. For example, the LRUMemoryCache will remove the numberToFree least recently used items. These will be spooled to disk if a disk auxiliary is available.- Specified by:
freeMemoryElements
in interfaceICacheAccessManagement
- Parameters:
numberToFree
-- Returns:
- the number that were removed. if you ask to free 5, but there are only 3, you will get 3.
- Throws:
CacheException
-
getCacheControl
-