Class LazyCacheController
- java.lang.Object
 - 
- com.broadleafcommerce.common.extension.cache.LazyCacheController
 
 
- 
public class LazyCacheController extends Object
Utility class for performing a cache related operation lazily if an expiration threshold has been met. This is generally used with flows that may benefit from compiling all related entities into cache at once. Although the default Apache Ignite cache mechanism stores cache members off-heap, caution should still be used when leveraging this feature, as enough items in memory can have consequences to available RAM for other caches.
Only enabled whenisEnabled()is true. Also, if enough time elapses since the last cache operation (exceedinggetExpiry()), a cache operation will be enacted.
Finally, the cache operation is performed asynchronously by default and the current flow will proceed un-blocked, unlessisBlocking()is true, in which case the request will block while the cache is populated. The cache operation is only allowed to be spawned whengetActive()is false in order to avoid multiple, concurrent cache operations.getActive()is true during the duration of a cache operation. 
- 
- 
Constructor Summary
Constructors Constructor Description LazyCacheController(boolean enabled, String name, Duration expiry, boolean blocking) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancanEqual(Object other)booleanequals(Object o)voidexecuteIfApplicable(boolean force, String region, Runnable cacheOperation)Run the operation based on the following conditions Only if enabled Only if there is not another operation currently running Only ifforceis true, or,isExpiryExceeded(String)is trueAtomicBooleangetActive()DurationgetExpiry()Map<String,AtomicLong>getExpiryTimestampByRegion()StringgetName()io.opentracing.TracergetTracer()inthashCode()booleanisBlocking()booleanisEnabled()booleanisExpiryExceeded(String region)Whether or not the standard cache TTL is smaller than the duration of time since the last cache generation operation timestamp.voidreset()Clear current expiries.voidsetActive(AtomicBoolean active)voidsetBlocking(boolean blocking)voidsetExpiryTimestampByRegion(Map<String,AtomicLong> expiryTimestampByRegion)voidsetTracer(io.opentracing.Tracer tracer)StringtoString()LazyCacheControllerwithTracer(io.opentracing.Tracer tracer) 
 - 
 
- 
- 
Method Detail
- 
isExpiryExceeded
public boolean isExpiryExceeded(String region)
Whether or not the standard cache TTL is smaller than the duration of time since the last cache generation operation timestamp.- Returns:
 - Whether or not the standard cache TTL is smaller than the duration of time since the last cache generation operation timestamp.
 
 
- 
reset
public void reset()
Clear current expiries. Has the effect of causing instant rejuvenation of the cache on the next request. 
- 
executeIfApplicable
public void executeIfApplicable(boolean force, String region, Runnable cacheOperation)Run the operation based on the following conditions- Only if enabled
 - Only if there is not another operation currently running
 - Only if 
forceis true, or,isExpiryExceeded(String)is true 
- Parameters:
 force- Whether or not to force the operation and ignore expiry checkscacheOperation- The cache related operation to perform. Generally, this will be code that tries to load a full list of entities into memory as a pre-emptive cache operation. However, it could be any appropriate cache operation.
 
- 
withTracer
public LazyCacheController withTracer(io.opentracing.Tracer tracer)
 
- 
isEnabled
public boolean isEnabled()
 
- 
getName
public String getName()
 
- 
getExpiry
public Duration getExpiry()
 
- 
isBlocking
public boolean isBlocking()
 
- 
getTracer
public io.opentracing.Tracer getTracer()
 
- 
getExpiryTimestampByRegion
public Map<String,AtomicLong> getExpiryTimestampByRegion()
 
- 
getActive
public AtomicBoolean getActive()
 
- 
setBlocking
public void setBlocking(boolean blocking)
 
- 
setTracer
public void setTracer(io.opentracing.Tracer tracer)
 
- 
setExpiryTimestampByRegion
public void setExpiryTimestampByRegion(Map<String,AtomicLong> expiryTimestampByRegion)
 
- 
setActive
public void setActive(AtomicBoolean active)
 
- 
canEqual
protected boolean canEqual(Object other)
 
 - 
 
 -