K - type of keys in this cacheV - type of values in this cachepublic final class EvictableCache<K,V> extends Object
| Modifier and Type | Class | Description |
|---|---|---|
static class |
EvictableCache.Builder<K,V> |
Builder to create instances of
EvictableCache. |
| Modifier and Type | Field | Description |
|---|---|---|
static long |
CACHE_EVICT_DELAY_MINUTES |
Default eviction delay in minutes (how long to wait after the cache is started).
|
static long |
CACHE_EVICT_PERIOD_MINUTES |
Default eviction period in minutes (how often to evict records).
|
static long |
CACHE_MAX_SIZE |
Maximal number of records in the cache.
|
static long |
CACHE_TIMEOUT_MINUTES |
Default timeout of records in minutes (inactivity timeout).
|
static long |
EVICT_PARALLELISM_THRESHOLD |
Parameter to
ConcurrentHashMap.forEachKey(long, Consumer) used for eviction. |
static int |
EVICT_THREAD_COUNT |
Number of threads in the scheduled thread pool to evict records.
|
| Modifier and Type | Method | Description |
|---|---|---|
static <K,V> EvictableCache.Builder<K,V> |
builder() |
Create a new builder for a cache.
|
void |
close() |
Close this cache.
|
Optional<V> |
computeValue(K key,
Supplier<Optional<V>> valueSupplier) |
Either return a cached value or compute it and cache it.
|
static <K,V> EvictableCache<K,V> |
create() |
Create a new cache with default values.
|
Optional<V> |
get(K key) |
Get current cached value if valid.
|
Optional<V> |
remove(K key) |
Remove a key from the cache.
|
int |
size() |
Current size of the cache.
|
public static final int EVICT_THREAD_COUNT
public static final long CACHE_TIMEOUT_MINUTES
public static final long CACHE_EVICT_PERIOD_MINUTES
public static final long CACHE_EVICT_DELAY_MINUTES
public static final long CACHE_MAX_SIZE
public static final long EVICT_PARALLELISM_THRESHOLD
ConcurrentHashMap.forEachKey(long, Consumer) used for eviction.public static <K,V> EvictableCache.Builder<K,V> builder()
K - type of keys in the cacheV - type of values in the cachepublic static <K,V> EvictableCache<K,V> create()
K - type of keys in the cacheV - type of values in the cachepublic Optional<V> remove(K key)
key - key to removepublic Optional<V> get(K key)
key - key to usepublic int size()
ConcurrentHashMap as backing store, be aware that this value is not
guaranteed to be consistent, as puts and removed may be happening in parallel.public Optional<V> computeValue(K key, Supplier<Optional<V>> valueSupplier)
key - key to check/insert value forvalueSupplier - supplier called if the value is not yet cached, or is invalidpublic void close()
Copyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.