Interface LocalCache


  • public interface LocalCache
    Framework service injectable in components or services methods to handle local caching. Useful for actions when deployed in a long running instance when actions are costly.
    • Method Detail

      • computeIfAbsent

        <T> T computeIfAbsent​(Class<T> expectedClass,
                              String key,
                              Predicate<LocalCache.Element> toRemove,
                              long timeoutMs,
                              Supplier<T> value)
        Read or compute and save a value for a determined duration and predicate.
        Type Parameters:
        T - class of cached instance.
        Parameters:
        expectedClass - : cached instance class.
        key - : the cache key, must be unique accross the server.
        toRemove - : is the object to be removed.
        timeoutMs - : duration of cache value.
        value - : the value provider if the cache get does a miss.
        Returns:
        the cached or newly computed value.
      • computeIfAbsent

        <T> T computeIfAbsent​(Class<T> expectedClass,
                              String key,
                              Predicate<LocalCache.Element> toRemove,
                              Supplier<T> value)
        Read or compute and save a value until remove predicate go to remove.
        Type Parameters:
        T - class of cached instance.
        Parameters:
        expectedClass - : cached instance class.
        key - : the cache key, must be unique accross the server.
        toRemove - : is the object to be removed.
        value - : the value provider if the cache get does a miss.
        Returns:
        the cached or newly computed value.
      • computeIfAbsent

        <T> T computeIfAbsent​(Class<T> expectedClass,
                              String key,
                              long timeoutMs,
                              Supplier<T> value)
        Read or compute and save a value for a determined duration.
        Type Parameters:
        T - class of cached instance.
        Parameters:
        expectedClass - : cached instance class.
        key - : the cache key, must be unique accross the server.
        timeoutMs - : duration of cache value.
        value - : value provider.
        Returns:
        the cached or newly computed value.
      • computeIfAbsent

        <T> T computeIfAbsent​(Class<T> expectedClass,
                              String key,
                              Supplier<T> value)
        Compute and save a value, if key not present, for undetermined duration.
        Type Parameters:
        T - class of cached instance.
        Parameters:
        expectedClass - : cached instance class.
        key - : the cache key, must be unique accross the server.
        value - : value provider.
        Returns:
        the cached or newly computed value.
      • evict

        void evict​(String key)
        Remove a cached entry.
        Parameters:
        key - key to evict.
      • evictIfValue

        void evictIfValue​(String key,
                          Object expected)
        Remove a cached entry if a particular value is in the cache.
        Parameters:
        key - key to evict.
        expected - expected value activating the eviction.