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.isEnabled()
is true. Also, if enough time elapses since the last cache operation (exceedinggetExpiry()
), a cache operation will be enacted.isBlocking()
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 boolean
canEqual(Object other)
boolean
equals(Object o)
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 ifforce
is true, or,isExpiryExceeded(String)
is trueAtomicBoolean
getActive()
Duration
getExpiry()
Map<String,AtomicLong>
getExpiryTimestampByRegion()
String
getName()
io.opentracing.Tracer
getTracer()
int
hashCode()
boolean
isBlocking()
boolean
isEnabled()
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.void
reset()
Clear current expiries.void
setActive(AtomicBoolean active)
void
setBlocking(boolean blocking)
void
setExpiryTimestampByRegion(Map<String,AtomicLong> expiryTimestampByRegion)
void
setTracer(io.opentracing.Tracer tracer)
String
toString()
LazyCacheController
withTracer(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
force
is 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)
-
-