K - the cache key typeV - the cache value type@ThreadSafe
public abstract class Cache<K,V>
extends java.lang.Object
implements java.io.Closeable
| Modifier and Type | Class and Description |
|---|---|
protected class |
Cache.Entry |
| Constructor and Description |
|---|
Cache(CacheConfiguration conf,
java.lang.String name) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears all entries from the map.
|
void |
close() |
void |
flush()
Flushes all data to the backing store.
|
protected abstract void |
flushEntries(java.util.List<Cache.Entry> candidates)
Attempts to flush the given entries to the backing store.
|
java.util.Optional<V> |
get(K key) |
java.util.Optional<V> |
get(K key,
ReadOption option)
Retrieves a value from the cache, loading it from the backing store if necessary.
|
protected java.util.Map<K,Cache.Entry> |
getCacheMap() |
protected abstract java.util.Optional<V> |
load(K key)
Loads a key from the backing store.
|
protected void |
onCacheRemove(K key)
Callback triggered when a key is removed from the cache.
|
protected void |
onCacheUpdate(K key,
V value)
Callback triggered when an update is made to a key/value pair in the cache.
|
protected void |
onPut(K key,
V value)
Callback triggered whenever a new key/value pair is added by put(key, value).
|
protected void |
onRemove(K key)
Callback triggered whenever a key is removed by remove(key).
|
void |
put(K key,
V value)
Writes a key/value pair to the cache.
|
void |
remove(K key)
Removes a key from the cache.
|
protected abstract void |
removeFromBackingStore(K key)
Removes a key from the backing store.
|
protected abstract void |
writeToBackingStore(K key,
V value)
Writes a key/value pair to the backing store.
|
public Cache(CacheConfiguration conf, java.lang.String name)
conf - cache configurationname - a name for the cachepublic java.util.Optional<V> get(K key, ReadOption option)
key - the key to get the value foroption - the read optionspublic java.util.Optional<V> get(K key)
key - the key to get the value forget(Object, ReadOption) with default optionpublic void put(K key, V value)
key - the keyvalue - the valuepublic void remove(K key)
key - the key to removepublic void flush()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic void clear()
public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableprotected java.util.Map<K,Cache.Entry> getCacheMap()
protected void onCacheUpdate(K key, @Nullable V value)
key - the updated keyvalue - the updated value, or null if the key is being removedprotected void onCacheRemove(K key)
key - the removed keyprotected void onPut(K key, V value)
key - the added keyvalue - the added valueprotected void onRemove(K key)
key - the removed keyprotected abstract java.util.Optional<V> load(K key)
key - the key to loadprotected abstract void writeToBackingStore(K key, V value)
key - the keyvalue - the valueprotected abstract void removeFromBackingStore(K key)
key - the keyprotected abstract void flushEntries(java.util.List<Cache.Entry> candidates)
candidates - the candidate entries to flushCopyright © 2019. All Rights Reserved.