Package com.clickhouse.client.cache
Class JdkLruCache<K,V>
- java.lang.Object
-
- com.clickhouse.client.cache.JdkLruCache<K,V>
-
- All Implemented Interfaces:
ClickHouseCache<K,V>
public class JdkLruCache<K,V> extends Object implements ClickHouseCache<K,V>
A simple thread-safe LRU cache based on LinkedHashMap. It's not as effient as the one in Caffeine/Guava, but it requires no extra dependency.
-
-
Field Summary
-
Fields inherited from interface com.clickhouse.client.ClickHouseCache
DEFAULT_CACHE_SIZE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <K,V>
ClickHouseCache<K,V>create(int capacity, Function<K,V> loadFunc)Creates a cache with given capacity and load function.Vget(K key)Gets value from cache if it exists.<T> Tunwrap(Class<T> clazz)Gets inner cache object to gain more access.
-
-
-
Method Detail
-
create
public static <K,V> ClickHouseCache<K,V> create(int capacity, Function<K,V> loadFunc)
Creates a cache with given capacity and load function.- Type Parameters:
K- type of the keyV- type of the value- Parameters:
capacity- capacityloadFunc- load function- Returns:
- cache
-
get
public V get(K key)
Description copied from interface:ClickHouseCacheGets value from cache if it exists.- Specified by:
getin 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:ClickHouseCacheGets inner cache object to gain more access.- Specified by:
unwrapin interfaceClickHouseCache<K,V>- Type Parameters:
T- type of the cache- Parameters:
clazz- non-null class of the cache- Returns:
- inner cache object
-
-