Class CaffeineCache<K,​V>

  • All Implemented Interfaces:
    Cache<K,​V>

    public class CaffeineCache<K,​V>
    extends Object
    implements Cache<K,​V>
    In-memory cache implementation that is a wrapper around a Caffeine cache.
    See Also:
    Caffeine
    • Constructor Detail

      • CaffeineCache

        public CaffeineCache​(com.github.benmanes.caffeine.cache.Cache cache)
    • Method Detail

      • get

        public V get​(K key,
                     Function<K,​V> loader)
        Retrieves a value from the cache. If it doesn't exist, the loader is called to load the object, which is then cached and returned.
        Specified by:
        get in interface Cache<K,​V>
        Parameters:
        key - to lookup in the cache
        loader - function to call to load the object if it's not found
        Returns:
        the object that maps to the key
      • put

        public void put​(K key,
                        V value)
        Inserts a value into the cache.
        Specified by:
        put in interface Cache<K,​V>
        Parameters:
        key - key
        value - value
      • invalidate

        public void invalidate​(K key)
        Invalidates the key in the cache.
        Specified by:
        invalidate in interface Cache<K,​V>
        Parameters:
        key - key
      • invalidateAll

        public void invalidateAll()
        Invalidates the entire cache
        Specified by:
        invalidateAll in interface Cache<K,​V>
      • contains

        public boolean contains​(K key)
        Returns true if the cache contains the specified key
        Specified by:
        contains in interface Cache<K,​V>
        Parameters:
        key - key
        Returns:
        true if the cache contains the key