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 Detail

      • 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
      • 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

        void invalidateAll()
        Discards all entries in the cache, without reseting statistics
      • resetCache

        void resetCache()
        Create or reset the whole cache (including statistics)
      • getCacheStats

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

        long getMemorySize()
                    throws CacheException
        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

        long getNumberOfElements()
        Get the number of values in cache
        Returns:
        the number of values in cache
      • getId

        String 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,​VasMap()
        Get the cache as a simple Map
        Returns:
        the Map<K, V> representing the cache
      • toJSONMap

        default Map<String,​ObjecttoJSONMap​(org.slf4j.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