Class LazyCacheController
java.lang.Object
com.broadleafcommerce.common.extension.cache.LazyCacheController
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 when
isEnabled()
is true. Also, if enough time elapses since the last cache
operation (exceeding getExpiry()
), a cache operation will be enacted.
Finally, the cache operation is performed asynchronously by default and the current flow will proceed un-blocked, unless
isBlocking()
is true, in which case the request will block
while the cache is populated. The cache operation is only allowed to be spawned when
getActive()
is false in order to avoid multiple, concurrent cache operations.
getActive()
is true during the duration of a cache operation.-
Constructor Summary
ConstructorDescriptionLazyCacheController
(boolean enabled, String name, Duration expiry, boolean blocking) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
boolean
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 truegetName()
io.opentracing.Tracer
int
hashCode()
boolean
boolean
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) toString()
withTracer
(io.opentracing.Tracer tracer)
-
Constructor Details
-
LazyCacheController
-
-
Method Details
-
isExpiryExceeded
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
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
-
isEnabled
public boolean isEnabled() -
getName
-
getExpiry
-
isBlocking
public boolean isBlocking() -
getTracer
public io.opentracing.Tracer getTracer() -
getExpiryTimestampByRegion
-
getActive
-
setBlocking
public void setBlocking(boolean blocking) -
setTracer
public void setTracer(io.opentracing.Tracer tracer) -
setExpiryTimestampByRegion
-
setActive
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-