Class CaffeineCache<K,​V>

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

    public class CaffeineCache<K,​V>
    extends Object
    implements ClickHouseCache<K,​V>
    Cache based on Caffeine implementation. Please be aware that it's not really a LRU cache.
    • Constructor Detail

      • CaffeineCache

        protected CaffeineCache​(int capacity,
                                long expireSeconds,
                                Function<K,​V> loadFunc)
    • Method Detail

      • create

        public static <K,​V> ClickHouseCache<K,​V> create​(int capacity,
                                                                    long expireSeconds,
                                                                    Function<K,​V> loadFunc)
        Creates a cache with given capacity, seconds to expire(after access), and load function.
        Type Parameters:
        K - type of the key
        V - type of the value
        Parameters:
        capacity - capacity of the cache
        expireSeconds - seconds to expire after access
        loadFunc - load function
        Returns:
        cache
      • get

        public V get​(K key)
        Description copied from interface: ClickHouseCache
        Gets value from cache if it exists.
        Specified by:
        get in interface ClickHouseCache<K,​V>
        Parameters:
        key - key, in genernal should NOT be null
        Returns:
        non-null value in general
      • unwrap

        public <T> T unwrap​(Class<T> clazz)
        Description copied from interface: ClickHouseCache
        Gets inner cache object to gain more access.
        Specified by:
        unwrap in interface ClickHouseCache<K,​V>
        Type Parameters:
        T - type of the cache
        Parameters:
        clazz - non-null class of the cache
        Returns:
        inner cache object