Class CloneLibCacheConcurrentMapWrapper
java.lang.Object
com.broadleafcommerce.enterprise.workflow.clone.CloneLibCacheConcurrentMapWrapper
- All Implemented Interfaces:
CloneLibCacheWrapper
CloneLibCacheWrapper implementation that uses a ConcurrentHashMap as the backing cache. This cache has high performance
and concurrency for gets. Adds are slightly less efficient because of some synchronization. Removals are even less efficient because of synchronization, but should constitute a much less
frequent circumstance.- Author:
- Jeff Fischer
- See Also:
-
Field Summary
FieldsFields inherited from interface com.broadleafcommerce.enterprise.workflow.clone.CloneLibCacheWrapper
MODE_COMPLETE, MODE_PARTIAL, MODE_UNSET -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd aWorkflowCloneLibraryinstance to the cache.voidAudit a cache member based on the key for ttl status.voidAudit the entire cache based on total size.booleanclear()Queue all items in the cache for removal.voidRemove a specific queued add item from the backing cache's add queue.voiddestroy()Perform any operations required to clean up the cache on container exit.Retrieve the list of all items currently queued for addition.getByCloneKey(String key) Retrieve an item from the backing cache using a fetch key based on the clone id.protected WorkflowCloneLibrarygetByOriginalKey(String key) Retrieve an item from the backing cache using a fetch key based on the original id.Retrieve an item from the backing cache using a fetch key based on the original id.intgetMode()Provide a threadlocal temporary cache.longRetrieve the number of unique members represented in the cache.booleanWhether or not there are any cache members queued for removal viaCloneLibCacheWrapper.reliableRemoveCacheItemGroup(Set).voidqueueForAdd(List<WorkflowCloneLibrary> group) Queue a group of elements for addition to the queue.voidAny cache items that have been reserved against the current thread will be released.voidRemove aWorkflowCloneLibraryinstance list from the cache.booleanremoveCacheItems(Set<WorkflowCloneLibrary> items) Remove aWorkflowCloneLibraryinstance list from the cache.reserveCacheItem(String key) Reserve a cache item using the key for the item.voidsetMode(int mode) Establish how the cache will deal with cache misses and manage the size of the cache.
-
Field Details
-
CLONELIB_REFRESH_CACHE
- See Also:
-
-
Constructor Details
-
CloneLibCacheConcurrentMapWrapper
public CloneLibCacheConcurrentMapWrapper(long maxSize, long ttl)
-
-
Method Details
-
clear
public boolean clear()Description copied from interface:CloneLibCacheWrapperQueue all items in the cache for removal. This should only be applied whenCloneLibCacheWrapper.getMode()isCloneLibCacheWrapper.MODE_PARTIAL.- Specified by:
clearin interfaceCloneLibCacheWrapper- Returns:
- queue the cache members for removal
-
addCacheItem
Description copied from interface:CloneLibCacheWrapperAdd aWorkflowCloneLibraryinstance to the cache.- Specified by:
addCacheItemin interfaceCloneLibCacheWrapper- Parameters:
item- an instance to add to the cache
-
queueForAdd
Description copied from interface:CloneLibCacheWrapperQueue a group of elements for addition to the queue. The group of elements should be present in the cache in their entirety (or not at all) at the time of a call toCloneLibCacheWrapper.getByCloneKey(String)orCloneLibCacheWrapper.getByOriginalKey(String).- Specified by:
queueForAddin interfaceCloneLibCacheWrapper- Parameters:
group- the group of items to add as a unit
-
dequeueForAdd
Description copied from interface:CloneLibCacheWrapperRemove a specific queued add item from the backing cache's add queue.- Specified by:
dequeueForAddin interfaceCloneLibCacheWrapper- Parameters:
item- the item to remove from the queue
-
getAddQueue
Description copied from interface:CloneLibCacheWrapperRetrieve the list of all items currently queued for addition.- Specified by:
getAddQueuein interfaceCloneLibCacheWrapper- Returns:
- the queued items
- See Also:
-
setMode
public void setMode(int mode) Description copied from interface:CloneLibCacheWrapperEstablish how the cache will deal with cache misses and manage the size of the cache. A mode ofCloneLibCacheWrapper.MODE_COMPLETEsignifies the cache is populated with the entire contents of the database table backing theWorkflowCloneLibraryImplentity. In this mode, cache misses are understood to not be present in the datastore and are not further managed in the cache. A mode ofCloneLibCacheWrapper.MODE_PARTIALsignifies the cache is only partially populated with the contents of the database table and new entries are added on demand. In this mode, cache misses are kept track of in the cache, which can result in larger overall cache sizes. A mode ofCloneLibCacheWrapper.MODE_UNSETsimply means the mode has not been specified, or has not yet been determined.CloneLibCacheWrapper.MODE_COMPLETEis useful in multitenant situations where there are many sites, but few site-level overrides. In such a situation, it is efficient to keep the entire override cache in memory. SeeCloneCache.fetchAllReferencesMaxMultifor more information on how to set the threshold for determining the number of cache members for whichCloneLibCacheWrapper.MODE_COMPLETEis qualified.CloneLibCacheWrapper.MODE_PARTIALis useful in multitenant scenarios where there are many site-level overrides, but only a portion of those overrides are accessed frequently. SeeCloneCache.defaultCacheImplementationMaxSizeHintandCloneCache.defaultCacheImplementationTtlMillisecondsfor more information on sizing hints to the system regarding max cache size and member time-to-live.- Specified by:
setModein interfaceCloneLibCacheWrapper- Parameters:
mode- the cache management mode
-
getMode
public int getMode()- Specified by:
getModein interfaceCloneLibCacheWrapper- Returns:
- the cache management mode
- See Also:
-
destroy
public void destroy()Description copied from interface:CloneLibCacheWrapperPerform any operations required to clean up the cache on container exit.- Specified by:
destroyin interfaceCloneLibCacheWrapper- See Also:
-
PreDestroy
-
reliableRemoveCacheItemGroup
Description copied from interface:CloneLibCacheWrapperRemove aWorkflowCloneLibraryinstance list from the cache. This removal will retry should the system be unable to initially remove one or more of the items from the cache. Possible reasons for not being able to remove include one or more of the removal requests targeting reserved items (seeCloneLibCacheWrapper.reserveCacheItem(String)).- Specified by:
reliableRemoveCacheItemGroupin interfaceCloneLibCacheWrapper- Parameters:
group- a representative instance list used to search the cache for matching cache members to remove
-
removeCacheItems
Description copied from interface:CloneLibCacheWrapperRemove aWorkflowCloneLibraryinstance list from the cache. May not succeed if an item in the list is currently reserved by another thread.- Specified by:
removeCacheItemsin interfaceCloneLibCacheWrapper- Parameters:
items- a representative instance list used to search the cache for matching cache members to remove- Returns:
- Whether or not the item was removed from the cache (either the item was not in the cache, or it was reserved by another thread)
-
reserveCacheItem
Description copied from interface:CloneLibCacheWrapperReserve a cache item using the key for the item. This reservation is against the current thread. Reserved items cannot be removed from the cache. If the item was successfully reserved, it is returned. Otherwise, it will return null.- Specified by:
reserveCacheItemin interfaceCloneLibCacheWrapper- Parameters:
key- the cache key- Returns:
- the cache member or null if not found
- See Also:
-
isRemovalQueueEmpty
public boolean isRemovalQueueEmpty()Description copied from interface:CloneLibCacheWrapperWhether or not there are any cache members queued for removal viaCloneLibCacheWrapper.reliableRemoveCacheItemGroup(Set).- Specified by:
isRemovalQueueEmptyin interfaceCloneLibCacheWrapper- Returns:
- if cache members are queued for removal
-
releaseCacheItems
public void releaseCacheItems()Description copied from interface:CloneLibCacheWrapperAny cache items that have been reserved against the current thread will be released. This has the impact of freeing up a cache item for removal should all reservations be released.- Specified by:
releaseCacheItemsin interfaceCloneLibCacheWrapper- See Also:
-
auditSize
public void auditSize()Description copied from interface:CloneLibCacheWrapperAudit the entire cache based on total size. Oldest cache members are removed first in order to reach the cache max size target. The system max a best-effort attempt to maintain a cache size that is not larger than the configured max size, but the cache size may occasionally be exceeded. Cache members that are reserved are not removed until released. This only applies to aCloneLibCacheWrapper.getMode()ofCloneLibCacheWrapper.MODE_PARTIAL.- Specified by:
auditSizein interfaceCloneLibCacheWrapper- See Also:
-
auditKey
Description copied from interface:CloneLibCacheWrapperAudit a cache member based on the key for ttl status. If the ttl for the item has expired, the cache member will be evicted if it is not reserved. This only applies to aCloneLibCacheWrapper.getMode()ofCloneLibCacheWrapper.MODE_PARTIAL.- Specified by:
auditKeyin interfaceCloneLibCacheWrapper- Parameters:
key- the cache key to check- See Also:
-
getByOriginalKey
Description copied from interface:CloneLibCacheWrapperRetrieve an item from the backing cache using a fetch key based on the original id.- Specified by:
getByOriginalKeyin interfaceCloneLibCacheWrapper- Parameters:
key- the cache item key- Returns:
- the cache member
-
getByCloneKey
Description copied from interface:CloneLibCacheWrapperRetrieve an item from the backing cache using a fetch key based on the clone id.- Specified by:
getByCloneKeyin interfaceCloneLibCacheWrapper- Parameters:
key- the cache item key- Returns:
- the cache member
-
getByOriginalKeyFromInternalCacheOnly
Description copied from interface:CloneLibCacheWrapperRetrieve an item from the backing cache using a fetch key based on the original id. This retrieval only utilizes the backing cache and does not look at theCloneLibCacheWrapper.getRefreshCache().- Specified by:
getByOriginalKeyFromInternalCacheOnlyin interfaceCloneLibCacheWrapper- Parameters:
key- the original key- Returns:
- the cache member
-
getUniqueElementCount
public long getUniqueElementCount()Description copied from interface:CloneLibCacheWrapperRetrieve the number of unique members represented in the cache. The backing cache may contain multiple keys per unique cache member, so this method should be used to determine the correct count of unique members.- Specified by:
getUniqueElementCountin interfaceCloneLibCacheWrapper- Returns:
- the unique member count
-
getRefreshCache
Provide a threadlocal temporary cache.- Specified by:
getRefreshCachein interfaceCloneLibCacheWrapper- Returns:
- temporary cache to hold reads for items queued for removal
-
getByKey
-