Package com.clickhouse.client.cache
Class CaffeineCache<K,V>
- java.lang.Object
-
- com.clickhouse.client.cache.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.
-
-
Field Summary
-
Fields inherited from interface com.clickhouse.client.ClickHouseCache
DEFAULT_CACHE_SIZE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CaffeineCache(int capacity, long expireSeconds, Function<K,V> loadFunc)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.V
get(K key)
Gets value from cache if it exists.<T> T
unwrap(Class<T> clazz)
Gets inner cache object to gain more access.
-
-
-
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 keyV
- type of the value- Parameters:
capacity
- capacity of the cacheexpireSeconds
- seconds to expire after accessloadFunc
- 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 interfaceClickHouseCache<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 interfaceClickHouseCache<K,V>
- Type Parameters:
T
- type of the cache- Parameters:
clazz
- non-null class of the cache- Returns:
- inner cache object
-
-