Class CompositeCache<K,V> 
- All Implemented Interfaces:
- ICache<K,,- V> - ICacheType,- IRequireScheduler
This is the core of a JCS region. Hence, this simple class is the core of JCS.
- 
Nested Class SummaryNested classes/interfaces inherited from interface org.apache.commons.jcs3.engine.behavior.ICacheTypeICacheType.CacheType
- 
Field SummaryFields inherited from interface org.apache.commons.jcs3.engine.behavior.ICacheNAME_COMPONENT_DELIMITER
- 
Constructor SummaryConstructorsConstructorDescriptionCompositeCache(ICompositeCacheAttributes cattr, IElementAttributes attr) Constructor for the Cache object
- 
Method SummaryModifier and TypeMethodDescriptionvoiddispose()Flushes all cache items from memory to auxiliary caches and close the auxiliary caches.voiddispose(boolean fromRemote) Invoked only by CacheManager.protected voiddoExpires(ICacheElement<K, V> element) Gets an item from the cache.protected ICacheElement<K,V> Look in memory, then disk, remote, or laterally for this item.List<AuxiliaryCache<K,V>> Get the list of auxiliary caches for this region.AuxiliaryCache<K,V>[] Deprecated.Use List methodGets the ICompositeCacheAttributes attribute of the Cache object.Gets the cacheName attribute of the Cache object.Gets the cacheType attribute of the Cache object.Gets the default element attribute of the Cache object This returns a copy.getElementAttributes(K key) Gets the elementAttributes attribute of the Cache object.longNumber of times a requested item was found in and auxiliary cache.longNumber of times a requested item was found in the memory cache.Returns the key matcher used by get matching.Get a set of the keys for all elements in the cachegetKeySet(boolean localOnly) Get a set of the keys for all elements in the cacheMap<K,ICacheElement<K, V>> getMatching(String pattern) Build a map of all the matching elements in all of the auxiliaries and memory.protected Map<K,ICacheElement<K, V>> getMatching(String pattern, boolean localOnly) Build a map of all the matching elements in all of the auxiliaries and memory.protected Map<K,ICacheElement<K, V>> getMatchingFromMemory(String pattern) Gets the key array from the memcache.Access to the memory cache for instrumentation.longNumber of times a requested element was found but was expired.longNumber of times a requested element was not found.Map<K,ICacheElement<K, V>> getMultiple(Set<K> keys) Gets multiple items from the cache based on the given set of keys.protected Map<K,ICacheElement<K, V>> getMultiple(Set<K> keys, boolean localOnly) Look in memory, then disk, remote, or laterally for these items.intgetSize()Gets the size attribute of the Cache object.This returns data gathered for this region and all the auxiliaries it currently uses.getStats()Gets stats for debugging.Gets the status attribute of the Cache object.longvoidhandleElementEvent(ICacheElement<K, V> element, ElementEventType eventType) If there are event handlers for the item, then create an event and queue it up.booleanisExpired(ICacheElement<K, V> element) Determine if the element is expired based on the values of the element attributesbooleanisExpired(ICacheElement<K, V> element, long timestamp, ElementEventType eventMaxlife, ElementEventType eventIdle) Check if the element is expired based on the values of the element attributesDo not try to go remote or laterally for this get.Map<K,ICacheElement<K, V>> localGetMatching(String pattern) Build a map of all the matching elements in all of the auxiliaries and memory.Map<K,ICacheElement<K, V>> localGetMultiple(Set<K> keys) Gets multiple items from the cache based on the given set of keys.booleanlocalRemove(K key) Do not propagate removeall laterally or remotely.voidWill not pass the remove message remotely.voidlocalUpdate(ICacheElement<K, V> ce) Standard update method.booleanRemoves an item from the cache.protected booleanfromRemote: If a remove call was made on a cache with both, then the remote should have been called.voidClears the region.protected voidremoveAll(boolean localOnly) Removes all cached items.voidsave()Calling save cause the entire contents of the memory cache to be flushed to all auxiliaries.voidsetAuxCaches(List<AuxiliaryCache<K, V>> auxCaches) This sets the list of auxiliary caches for this region.voidsetAuxCaches(AuxiliaryCache<K, V>[] auxCaches) Deprecated.Use List methodvoidSets the ICompositeCacheAttributes attribute of the Cache object.voidInjector for cache managervoidSets the default element attribute of the Cache object.voidInjector for Element event queuevoidsetKeyMatcher(IKeyMatcher<K> keyMatcher) Sets the key matcher used by get matching.voidsetScheduledExecutorService(ScheduledExecutorService scheduledExecutor) Inject an instance of a central ScheduledExecutorServicevoidspoolToDisk(ICacheElement<K, V> ce) Writes the specified element to any disk auxiliaries.toString()This returns the stats.voidupdate(ICacheElement<K, V> ce) Standard update method.protected voidupdate(ICacheElement<K, V> cacheElement, boolean localOnly) Put an item into the cache.protected voidupdateAuxiliaries(ICacheElement<K, V> cacheElement, boolean localOnly) This method is responsible for updating the auxiliaries if they are present.
- 
Constructor Details- 
CompositeCacheConstructor for the Cache object- Parameters:
- cattr- The cache attribute
- attr- The default element attributes
 
 
- 
- 
Method Details- 
setElementEventQueueInjector for Element event queue- Parameters:
- queue-
 
- 
setCompositeCacheManagerInjector for cache manager- Parameters:
- manager-
 
- 
setScheduledExecutorServiceDescription copied from interface:IRequireSchedulerInject an instance of a central ScheduledExecutorService- Specified by:
- setScheduledExecutorServicein interface- IRequireScheduler
- See Also:
 
- 
setAuxCachesThis sets the list of auxiliary caches for this region. It filters out null caches- Parameters:
- auxCaches-
- Since:
- 3.1
 
- 
setAuxCachesDeprecated.Use List methodThis sets the list of auxiliary caches for this region.- Parameters:
- auxCaches-
 
- 
getAuxCacheListGet the list of auxiliary caches for this region.- Returns:
- a list of auxiliary caches, may be empty, never null
- Since:
- 3.1
 
- 
getAuxCachesDeprecated.Use List methodGet the list of auxiliary caches for this region.- Returns:
- an array of auxiliary caches, may be empty, never null
 
- 
updateStandard update method.- Specified by:
- updatein interface- ICache<K,- V> 
- Parameters:
- ce-
- Throws:
- IOException
 
- 
localUpdateStandard update method.- Parameters:
- ce-
- Throws:
- IOException
 
- 
updatePut an item into the cache. If it is localOnly, then do no notify remote or lateral auxiliaries.- Parameters:
- cacheElement- the ICacheElement<K, V>
- localOnly- Whether the operation should be restricted to local auxiliaries.
- Throws:
- IOException
 
- 
updateAuxiliariesprotected void updateAuxiliaries(ICacheElement<K, V> cacheElement, boolean localOnly) throws IOExceptionThis method is responsible for updating the auxiliaries if they are present. If it is local only, any lateral and remote auxiliaries will not be updated.Before updating an auxiliary it checks to see if the element attributes permit the operation. Disk auxiliaries are only updated if the disk cache is not merely used as a swap. If the disk cache is merely a swap, then items will only go to disk when they overflow from memory. This is called by update(cacheElement, localOnly) after it updates the memory cache. This is protected to make it testable. - Parameters:
- cacheElement-
- localOnly-
- Throws:
- IOException
 
- 
spoolToDiskWrites the specified element to any disk auxiliaries. Might want to rename this "overflow" in case the hub wants to do something else.If JCS is not configured to use the disk as a swap, that is if the CompositeCacheAttribute diskUsagePattern is not SWAP_ONLY, then the item will not be spooled. - Parameters:
- ce- The CacheElement
 
- 
getGets an item from the cache.
- 
localGetDo not try to go remote or laterally for this get.- Parameters:
- key-
- Returns:
- ICacheElement
 
- 
getLook in memory, then disk, remote, or laterally for this item. The order is dependent on the order in the cache.ccf file.Do not try to go remote or laterally for this get if it is localOnly. Otherwise try to go remote or lateral if such an auxiliary is configured for this region. - Parameters:
- key-
- localOnly-
- Returns:
- ICacheElement
 
- 
doExpires
- 
getMultipleGets multiple items from the cache based on the given set of keys.- Specified by:
- getMultiplein interface- ICache<K,- V> 
- Parameters:
- keys-
- Returns:
- a map of K key to ICacheElement<K, V> element, or an empty map if there is no data in cache for any of these keys
 
- 
localGetMultipleGets multiple items from the cache based on the given set of keys. Do not try to go remote or laterally for this data.- Parameters:
- keys-
- Returns:
- a map of K key to ICacheElement<K, V> element, or an empty map if there is no data in cache for any of these keys
 
- 
getMultipleLook in memory, then disk, remote, or laterally for these items. The order is dependent on the order in the cache.ccf file. Keep looking in each cache location until either the element is found, or the method runs out of places to look.Do not try to go remote or laterally for this get if it is localOnly. Otherwise try to go remote or lateral if such an auxiliary is configured for this region. - Parameters:
- keys-
- localOnly-
- Returns:
- ICacheElement
 
- 
getMatchingBuild a map of all the matching elements in all of the auxiliaries and memory.- Specified by:
- getMatchingin interface- ICache<K,- V> 
- Parameters:
- pattern-
- Returns:
- a map of K key to ICacheElement<K, V> element, or an empty map if there is no data in cache for any matching keys
 
- 
localGetMatchingBuild a map of all the matching elements in all of the auxiliaries and memory. Do not try to go remote or laterally for this data.- Parameters:
- pattern-
- Returns:
- a map of K key to ICacheElement<K, V> element, or an empty map if there is no data in cache for any matching keys
 
- 
getMatchingBuild a map of all the matching elements in all of the auxiliaries and memory. Items in memory will replace from the auxiliaries in the returned map. The auxiliaries are accessed in opposite order. It's assumed that those closer to home are better.Do not try to go remote or laterally for this get if it is localOnly. Otherwise try to go remote or lateral if such an auxiliary is configured for this region. - Parameters:
- pattern-
- localOnly-
- Returns:
- a map of K key to ICacheElement<K, V> element, or an empty map if there is no data in cache for any matching keys
 
- 
getMatchingFromMemoryGets the key array from the memcache. Builds a set of matches. Calls getMultiple with the set. Returns a map: key -> result.- Parameters:
- pattern-
- Returns:
- a map of K key to ICacheElement<K, V> element, or an empty map if there is no data in cache for any matching keys
- Throws:
- IOException
 
- 
getKeySetGet a set of the keys for all elements in the cache- Returns:
- A set of the key type
 
- 
getKeySetGet a set of the keys for all elements in the cache- Parameters:
- localOnly- true if only memory keys are requested
- Returns:
- A set of the key type
 
- 
removeRemoves an item from the cache.
- 
localRemoveDo not propagate removeall laterally or remotely.- Parameters:
- key-
- Returns:
- true if the item was already in the cache.
 
- 
removefromRemote: If a remove call was made on a cache with both, then the remote should have been called. If it wasn't then the remote is down. we'll assume it is down for all. If it did come from the remote then the cache is remotely configured and lateral removal is unnecessary. If it came laterally then lateral removal is unnecessary. Does this assume that there is only one lateral and remote for the cache? Not really, the initial removal should take care of the problem if the source cache was similarly configured. Otherwise the remote cache, if it had no laterals, would remove all the elements from remotely configured caches, but if those caches had some other weird laterals that were not remotely configured, only laterally propagated then they would go out of synch. The same could happen for multiple remotes. If this looks necessary we will need to build in an identifier to specify the source of a removal.- Parameters:
- key-
- localOnly-
- Returns:
- true if the item was in the cache, else false
 
- 
removeAllClears the region. This command will be sent to all auxiliaries. Some auxiliaries, such as the JDBC disk cache, can be configured to not honor removeAll requests.- Specified by:
- removeAllin interface- ICache<K,- V> 
- Throws:
- IOException
- See Also:
 
- 
localRemoveAllWill not pass the remove message remotely.- Throws:
- IOException
 
- 
removeAllRemoves all cached items.- Parameters:
- localOnly- must pass in false to get remote and lateral aux's updated. This prevents looping.
- Throws:
- IOException
 
- 
disposeFlushes all cache items from memory to auxiliary caches and close the auxiliary caches.
- 
disposeInvoked only by CacheManager. This method disposes of the auxiliaries one by one. For the disk cache, the items in memory are freed, meaning that they will be sent through the overflow channel to disk. After the auxiliaries are disposed, the memory cache is disposed.- Parameters:
- fromRemote-
 
- 
saveCalling save cause the entire contents of the memory cache to be flushed to all auxiliaries. Though this put is extremely fast, this could bog the cache and should be avoided. The dispose method should call a version of this. Good for testing.
- 
getSizeGets the size attribute of the Cache object. This return the number of elements, not the byte size.
- 
getCacheTypeGets the cacheType attribute of the Cache object.- Specified by:
- getCacheTypein interface- ICacheType
- Returns:
- The cacheType value
 
- 
getStatusGets the status attribute of the Cache object.
- 
getStatsGets stats for debugging.
- 
getStatisticsThis returns data gathered for this region and all the auxiliaries it currently uses.- Returns:
- Statistics and Info on the Region.
 
- 
getCacheNameGets the cacheName attribute of the Cache object. This is also known as the region name.- Specified by:
- getCacheNamein interface- ICache<K,- V> 
- Returns:
- The cacheName value
 
- 
getElementAttributesGets the default element attribute of the Cache object This returns a copy. It does not return a reference to the attributes.- Returns:
- The attributes value
 
- 
setElementAttributesSets the default element attribute of the Cache object.- Parameters:
- attr-
 
- 
getCacheAttributesGets the ICompositeCacheAttributes attribute of the Cache object.- Returns:
- The ICompositeCacheAttributes value
 
- 
setCacheAttributesSets the ICompositeCacheAttributes attribute of the Cache object.- Parameters:
- cattr- The new ICompositeCacheAttributes value
 
- 
getElementAttributesGets the elementAttributes attribute of the Cache object.- Parameters:
- key-
- Returns:
- The elementAttributes value
- Throws:
- CacheException
- IOException
 
- 
isExpiredDetermine if the element is expired based on the values of the element attributes- Parameters:
- element- the element
- Returns:
- true if the element is expired
 
- 
isExpiredpublic boolean isExpired(ICacheElement<K, V> element, long timestamp, ElementEventType eventMaxlife, ElementEventType eventIdle) Check if the element is expired based on the values of the element attributes- Parameters:
- element- the element
- timestamp- the timestamp to compare to
- eventMaxlife- the event to fire in case the max life time is exceeded
- eventIdle- the event to fire in case the idle time is exceeded
- Returns:
- true if the element is expired
 
- 
handleElementEventIf there are event handlers for the item, then create an event and queue it up.This does not call handle directly; instead the handler and the event are put into a queue. This prevents the event handling from blocking normal cache operations. - Parameters:
- element- the item
- eventType- the event type
 
- 
getMemoryCacheAccess to the memory cache for instrumentation.- Returns:
- the MemoryCache implementation
 
- 
getHitCountRamNumber of times a requested item was found in the memory cache.- Returns:
- number of hits in memory
 
- 
getHitCountAuxNumber of times a requested item was found in and auxiliary cache.- Returns:
- number of auxiliary hits.
 
- 
getMissCountNotFoundNumber of times a requested element was not found.- Returns:
- number of misses.
 
- 
getMissCountExpiredNumber of times a requested element was found but was expired.- Returns:
- number of found but expired gets.
 
- 
getUpdateCount- Returns:
- Returns the updateCount.
 
- 
setKeyMatcherSets the key matcher used by get matching.- Specified by:
- setKeyMatcherin interface- ICache<K,- V> 
- Parameters:
- keyMatcher-
 
- 
getKeyMatcherReturns the key matcher used by get matching.- Returns:
- keyMatcher
 
- 
toStringThis returns the stats.
 
-