Class CacheStateManager
java.lang.Object
com.broadleafcommerce.common.extension.cache.CacheStateManager
Provides functionality to support interaction with the CacheManager. This includes detection of
ability to cache, as well as cache acquisition functionality.
- Author:
- Jeff Fischer
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final org.springframework.cache.Cache.ValueWrapper
-
Constructor Summary
ConstructorDescriptionCacheStateManager
(org.springframework.cache.CacheManager cacheManager, RoundedInstantFactory roundedInstantFactory, List<CacheStateConfigurer> configurers, List<CacheResultPostProcessor> postProcessors) -
Method Summary
Modifier and TypeMethodDescription<P> List<P>
computeIfAbsent
(Function<List<String>, List<P>> computeFunction, ImperativeListCacheInfo cacheInfo) Given aFunction
instance meant to generate values that are cacheable, check the cache using keys based on a collection of imperative key fragments.<P> P
computeIfAbsent
(Supplier<P> computeFunction, CacheInfo cacheInfo) Given aSupplier
instance meant to generate values that are cacheable, check the cache using a key based on a collection of key fragments.evict
(String cacheName, EntityInfo entityInfo) Evict a discrete cache member<P> P
Given the supplied cacheInfo object, return an object if it is in the cache.void
invalidate
(String cacheName) Invalidate an entire cache region, effectively evicting every member contained in that cacheboolean
Whether or not cache should be leveraged for the current call using the candidate caches.boolean
Whether or not cache should be leveraged for the current call using the candidate caches.boolean
Whether or not the cache should be ignored and all members computed and placed into cache.
-
Field Details
-
NULL_VALUE_WRAPPER
public static final org.springframework.cache.Cache.ValueWrapper NULL_VALUE_WRAPPER -
KEY_LIST
- See Also:
-
-
Constructor Details
-
CacheStateManager
public CacheStateManager(org.springframework.cache.CacheManager cacheManager, RoundedInstantFactory roundedInstantFactory, List<CacheStateConfigurer> configurers, List<CacheResultPostProcessor> postProcessors)
-
-
Method Details
-
isEnabled
Whether or not cache should be leveraged for the current call using the candidate caches.- Parameters:
caches
- The caches to evaluate for enablement for the current call.- Returns:
- Whether or not cache should be leveraged.
-
isEnabled
Whether or not cache should be leveraged for the current call using the candidate caches.- Parameters:
caches
- The caches to evaluate for enablement for the current call.params
- The params passed to that method.- Returns:
- Whether or not cache should be leveraged.
-
isForceCompile
public boolean isForceCompile()Whether or not the cache should be ignored and all members computed and placed into cache.- Returns:
- Whether or not the cache should be ignored and all members computed and placed into cache.
-
computeIfAbsent
public <P> List<P> computeIfAbsent(@NonNull Function<List<String>, List<P>> computeFunction, @NonNull ImperativeListCacheInfo cacheInfo) Given aFunction
instance meant to generate values that are cacheable, check the cache using keys based on a collection of imperative key fragments. If a cache value is available for the complex key generated based on one of the imperative keys combined with theargs
, then that cache value is used. Any cached values not found will utilize thecomputeFunction
to generate the uncached values, and those generated values will be cached. The sum of originally found cache and generated values are returned.CacheResultPostProcessor
, which are executed before results are returned from here.- Type Parameters:
P
- The return type- Parameters:
computeFunction
- TheFunction
instance responsible for generating uncached valuescacheInfo
- Required information to generate keys and interact with theCacheManager
.- Returns:
- The sum of cache hits and generated values
-
computeIfAbsent
Given aSupplier
instance meant to generate values that are cacheable, check the cache using a key based on a collection of key fragments. If a cache value is available for the complex key generated based on theargs
, then that cache value is used. If a cached values is not found it will utilize thecomputeFunction
to generate the uncached value, and that generated value will be cached. The cached or generated value is returned. Also, additional processing can be universally applied via one or more implementations ofCacheResultPostProcessor
, which are executed before the result is returned from here.- Type Parameters:
P
- The return type- Parameters:
computeFunction
- TheFunction
instance responsible for generating uncached valuescacheInfo
- Required information to generate keys and interact with theCacheManager
.- Returns:
- The sum of cache hits and generated values
-
get
Given the supplied cacheInfo object, return an object if it is in the cache.- Parameters:
cacheInfo
- Required information to generate keys and interact with theCacheManager
.- Returns:
- The object if it is in the cache, otherwise null.
-
evict
public Map<String,org.springframework.cache.Cache.ValueWrapper> evict(String cacheName, EntityInfo entityInfo) Evict a discrete cache member- Parameters:
cacheName
- The name of the cache regionentityInfo
- The identifying information for the specific entity-related cache to evict- Returns:
- Map of all cache members evicted from the cache, arranged by the cache key string value.
-
invalidate
Invalidate an entire cache region, effectively evicting every member contained in that cache- Parameters:
cacheName
- The cache region to invalidate
-