Interface Cache<K,V>

Type Parameters:
K - the type of the keys in cache
V - the type of the values in cache
All Known Implementing Classes:
GuavaCache

public interface Cache<K,V>
A cache represents a store of objects indexed with a key
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the cache as a simple Map
    get(K key)
    Returns the value associated with key in this cache if it exist
    get(K key, Function<K,V> function)
    Returns the value associated with key in this cache if it exist, obtaining that value from given function if necessary and store it.
    Get the cache as a simple Map, filtered by filled values of the cache key
    Get all statistics about cache
    Get the description of cache
    Get the id of cache
    Get the label of cache
    long
    Get the max size allocated to the cache, in bytes.
    long
    Get the size the cache take in bytes
    long
    Get the number of values in cache
    boolean
    hasKey(K key)
    return true if key is present in cache
    void
    Discards any cached value for key key.
    void
    Discards all entries in the cache, without reseting statistics
    boolean
    Is this cache size computable
    boolean
    Can the cache be transmitted in sub-requests of DispatchGenerator
    boolean
    Is this cache filled at least once.
    void
    put(K key, V value)
    Associates value with key in this cache.
    void
    putAll(Map<K,V> map)
    Copies all of the mappings from the specified map to the cache.
    void
    Create or reset the whole cache (including statistics).
    The CACHE_RESET event is not notified by this method, but should be by callers.
    default Map<String,Object>
    toJSONMap(Logger logger)
    Get the definition in JSON Map
  • Method Details

    • get

      V get(K key, Function<K,V> function) throws CacheException
      Returns the value associated with key in this cache if it exist, obtaining that value from given function if necessary and store it.
      Parameters:
      key - the key to get the element
      function - the function to compute the value if key is not present
      Returns:
      V the value associated with key
      Throws:
      CacheException - throw CacheException if the key is null or invalid, or if failed to compute the new value
    • get

      V get(K key)
      Returns the value associated with key in this cache if it exist
      Parameters:
      key - the key to get the element
      Returns:
      V the value linked to key
    • getAll

      Get the cache as a simple Map, filtered by filled values of the cache key
      Parameters:
      key - the key to get the element.
      Returns:
      the Map<K, V> representing the cache
    • put

      void put(K key, V value)
      Associates value with key in this cache. If the cache previously contained a value associated with key, the old value is replaced by value. The key can not be null.
      Parameters:
      key - the key to get the element
      value - the value associated with key
    • putAll

      void putAll(Map<K,V> map)
      Copies all of the mappings from the specified map to the cache.
      Parameters:
      map - map of key/values to be stored in the cache
    • hasKey

      boolean hasKey(K key)
      return true if key is present in cache
      Parameters:
      key - the key to be checked
      Returns:
      true if key is present in cache
    • invalidate

      void invalidate(K key)
      Discards any cached value for key key.
      Parameters:
      key - the key to invalidate
    • invalidateAll

      Discards all entries in the cache, without reseting statistics
    • resetCache

      void resetCache()
      Create or reset the whole cache (including statistics).
      The CACHE_RESET event is not notified by this method, but should be by callers.
    • getCacheStats

      Get all statistics about cache
      Returns:
      statistic about the cache (hit, miss, evictions...)
    • getMemorySize

      Get the size the cache take in bytes
      Returns:
      the size of the cache if it's computable, return 0 otherwise
      Throws:
      CacheException - throw CacheException if memory size can not be computed
    • getMaxSize

      long getMaxSize()
      Get the max size allocated to the cache, in bytes. This value can be set to Long.MAX_VALUE for infinite cache
      Returns:
      the max size allocated to the cache
    • getNumberOfElements

      Get the number of values in cache
      Returns:
      the number of values in cache
    • getLabel

      Get the label of cache
      Returns:
      the label of cache
    • getDescription

      Get the description of cache
      Returns:
      the description of cache
    • getId

      Get the id of cache
      Returns:
      the id of cache
    • isComputableSize

      boolean isComputableSize()
      Is this cache size computable
      Returns:
      true if the cache size is computable
    • asMap

      Map<K,V> asMap()
      Get the cache as a simple Map
      Returns:
      the Map<K, V> representing the cache
    • toJSONMap

      default Map<String,Object> toJSONMap(Logger logger)
      Get the definition in JSON Map
      Parameters:
      logger - Logger to log an error when the size cannot be computed
      Returns:
      the JSON for the cache
    • isInitialized

      boolean isInitialized()
      Is this cache filled at least once.
      Returns:
      true if the cache have been filled (put or putAll have been called even without values), false when the cache is new, reseted or if all values have been cleaned
    • isDispatchable

      boolean isDispatchable()
      Can the cache be transmitted in sub-requests of DispatchGenerator
      Returns:
      true if the cache can be transmitted in sub-requests of DispatchGenerator