
public abstract class AbstractLruCache<K,V> extends Object implements InterfaceLruCache<K,V>
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractLruCache(long ttl)
Constructs BaseLruCache
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(K key)
Checks whether cache contains valid entry for key
|
protected InterfaceLruCacheEntry<V> |
createEntry(V value,
long ttl)
Creates new LruCacheEntry
|
V |
get(K key)
Returns value cached with key.
|
V |
get(K key,
Callable<V> callback)
Tries to get element from cache.
|
V |
get(K key,
Callable<V> callback,
long ttl)
Tries to get element from cache.
|
protected abstract InterfaceLruCacheEntry<V> |
getEntry(K key)
Returns LruCacheEntry mapped by key or null if it does not exist
|
long |
getTtl()
Returns cache TTL
|
protected V |
getValue(K key)
Tries to retrieve value by it's key.
|
boolean |
isEmpty()
Checks whether cache is empty.
|
void |
put(K key,
V value)
Puts value under key into cache.
|
void |
put(K key,
V value,
long ttl)
Puts value under key into cache with desired TTL
|
protected abstract void |
putEntry(K key,
InterfaceLruCacheEntry<V> entry)
Puts entry into cache
|
void |
setNewTtl(long ttl)
Set a new TTL (for newly set objects only, not changing old values).
|
void |
updateTtl(K key)
Update the TTL of the associated object if it still exists
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclear, forceClearOldest, getCapacity, remove, size, valuesprotected AbstractLruCache(long ttl)
ttl - IllegalArgumentException - if ttl is not positivepublic final boolean contains(K key)
InterfaceLruCachecontains in interface InterfaceLruCache<K,V>protected InterfaceLruCacheEntry<V> createEntry(V value, long ttl)
It can be used to change implementation of LruCacheEntry
value - ttl - public V get(K key)
InterfaceLruCacheget in interface InterfaceLruCache<K,V>public final V get(K key, Callable<V> callback) throws Exception
InterfaceLruCacheDefault TTL is used
get in interface InterfaceLruCache<K,V>Exception - if callback throws exceptionpublic final V get(K key, Callable<V> callback, long ttl) throws Exception
InterfaceLruCacheget in interface InterfaceLruCache<K,V>ttl - time to live in millisecondsException - if callback throws exceptionpublic final long getTtl()
InterfaceLruCachegetTtl in interface InterfaceLruCache<K,V>public final void setNewTtl(long ttl)
InterfaceLruCachesetNewTtl in interface InterfaceLruCache<K,V>protected abstract InterfaceLruCacheEntry<V> getEntry(K key)
key - public final void updateTtl(K key)
InterfaceLruCacheupdateTtl in interface InterfaceLruCache<K,V>protected final V getValue(K key)
key - public final boolean isEmpty()
InterfaceLruCacheIf any entry exists (including invalid one) this method will return true
isEmpty in interface InterfaceLruCache<K,V>public final void put(K key, V value)
InterfaceLruCacheput in interface InterfaceLruCache<K,V>public void put(K key, V value, long ttl)
InterfaceLruCacheput in interface InterfaceLruCache<K,V>ttl - time to live in millisecondsprotected abstract void putEntry(K key, InterfaceLruCacheEntry<V> entry)
key - entry - Copyright © 2009–2022 Waarp. All rights reserved.