Class 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 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 Detail

      • LazyCacheController

        public LazyCacheController​(boolean enabled,
                                   String name,
                                   Duration expiry,
                                   boolean blocking)
    • 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
        1. Only if enabled
        2. Only if there is not another operation currently running
        3. Only if force is true, or, isExpiryExceeded(String) is true
        Parameters:
        force - Whether or not to force the operation and ignore expiry checks
        cacheOperation - 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.
      • isEnabled

        public boolean isEnabled()
      • getName

        public String getName()
      • getExpiry

        public Duration getExpiry()
      • isBlocking

        public boolean isBlocking()
      • getTracer

        public io.opentracing.Tracer getTracer()
      • setBlocking

        public void setBlocking​(boolean blocking)
      • setTracer

        public void setTracer​(io.opentracing.Tracer tracer)
      • setExpiryTimestampByRegion

        public void setExpiryTimestampByRegion​(Map<String,​AtomicLong> expiryTimestampByRegion)
      • canEqual

        protected boolean canEqual​(Object other)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object