public interface Cache<K,V>
This class is an internal implementation detail only intended for use within spectator. It is subject to change without notice.
Modifier and Type | Method and Description |
---|---|
Map<K,V> |
asMap()
Returns a map containing a snapshot of the cache.
|
void |
clear()
Remove all entries from the cache.
|
V |
computeIfAbsent(K key,
Function<K,V> f)
Returns the cached value associated with the key if present, otherwise computes a value
using the provided function.
|
V |
get(K key)
Returns the cached value associated with the key or null if none is found.
|
static <K1,V1> Cache<K1,V1> |
lfu(Registry registry,
String id,
int baseSize,
int compactionSize)
Create a new cache instance that removes the least frequently used items when full.
|
V |
peek(K key)
Like
get(Object) , but does not update the access count. |
void |
put(K key,
V value)
Add or overwrite the cache entry for the key.
|
int |
size() |
static <K1,V1> Cache<K1,V1> lfu(Registry registry, String id, int baseSize, int compactionSize)
registry
- Registry to use for tracking stats about the cache.id
- Used with metrics to indentify a particular instance of the cache.baseSize
- Number of items that should always be kept around in the cache.compactionSize
- Maximum size of the underlying map for the cache.V peek(K key)
get(Object)
, but does not update the access count.V computeIfAbsent(K key, Function<K,V> f)
key
- Id to use for looking up a value in the cache.f
- Function to compute a value based on the key. This function may get called multiple
times on a cache miss with some results getting discarded.void clear()
int size()