K - type of keys in this cacheV - type of values in this cachepublic interface EvictableCache<K,V>
| Modifier and Type | Interface | 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. |
| Modifier and Type | Method | Description |
|---|---|---|
static <K,V> EvictableCache.Builder<K,V> |
builder() |
Create a new builder for a cache.
|
default void |
close() |
Close this cache.
|
default java.util.Optional<V> |
computeValue(K key,
java.util.function.Supplier<java.util.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.
|
static <K,V> EvictableCache<K,V> |
create(Config config) |
Create a new cache and configure it from the provided configuration.
|
static <K,V> EvictableCache<K,V> |
from(Config config) |
Deprecated.
Do not use directly, please use
create(Config) |
default java.util.Optional<V> |
get(K key) |
Get current cached value if valid.
|
static <K,V> EvictableCache<K,V> |
noCache() |
Create a new cache that is not a cache (e.g.
|
default java.util.Optional<V> |
remove(K key) |
Remove a key from the cache.
|
default int |
size() |
Current size of the cache.
|
static final long CACHE_TIMEOUT_MINUTES
static final long CACHE_EVICT_PERIOD_MINUTES
static final long CACHE_EVICT_DELAY_MINUTES
static final long CACHE_MAX_SIZE
static final long EVICT_PARALLELISM_THRESHOLD
ConcurrentHashMap.forEachKey(long, Consumer) used for eviction.static <K,V> EvictableCache.Builder<K,V> builder()
K - type of keys in the cacheV - type of values in the cachestatic <K,V> EvictableCache<K,V> create()
K - type of keys in the cacheV - type of values in the cachestatic <K,V> EvictableCache<K,V> create(Config config)
EvictableCache.Builder.fromConfig(Config) for the list of configuration keys.K - type of keys in the cacheV - type of values in the cacheconfig - config to read configuration of this cache from@Deprecated static <K,V> EvictableCache<K,V> from(Config config)
create(Config)create(Config) and is here to allow automatic
loading of instances from config using Config.as(Class).K - type of keys in the cacheV - type of values in the cacheconfig - config to read configuration of this cache fromstatic <K,V> EvictableCache<K,V> noCache()
Supplier in computeValue(Object, Supplier).K - Type of keysV - Type of valuesdefault java.util.Optional<V> remove(K key)
key - key to removedefault java.util.Optional<V> get(K key)
key - key to usedefault 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.default java.util.Optional<V> computeValue(K key, java.util.function.Supplier<java.util.Optional<V>> valueSupplier)
key - key to check/insert value forvalueSupplier - supplier called if the value is not yet cached, or is invaliddefault void close()
Copyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.