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, wait
clear, forceClearOldest, getCapacity, remove, size
protected AbstractLruCache(long ttl)
ttl
- IllegalArgumentException
- if ttl is not positivepublic boolean contains(K key)
InterfaceLruCache
contains
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)
InterfaceLruCache
get
in interface InterfaceLruCache<K,V>
public V get(K key, Callable<V> callback) throws Exception
InterfaceLruCache
Default TTL is used
get
in interface InterfaceLruCache<K,V>
Exception
- if callback throws exceptionpublic V get(K key, Callable<V> callback, long ttl) throws Exception
InterfaceLruCache
get
in interface InterfaceLruCache<K,V>
ttl
- time to live in millisecondsException
- if callback throws exceptionpublic long getTtl()
InterfaceLruCache
getTtl
in interface InterfaceLruCache<K,V>
public void setNewTtl(long ttl)
InterfaceLruCache
setNewTtl
in interface InterfaceLruCache<K,V>
protected abstract InterfaceLruCacheEntry<V> getEntry(K key)
key
- public void updateTtl(K key)
InterfaceLruCache
updateTtl
in interface InterfaceLruCache<K,V>
protected V getValue(K key)
key
- public boolean isEmpty()
InterfaceLruCache
If any entry exists (including invalid one) this method will return true
isEmpty
in interface InterfaceLruCache<K,V>
public void put(K key, V value)
InterfaceLruCache
put
in interface InterfaceLruCache<K,V>
public void put(K key, V value, long ttl)
InterfaceLruCache
put
in interface InterfaceLruCache<K,V>
ttl
- time to live in millisecondsprotected abstract void putEntry(K key, InterfaceLruCacheEntry<V> entry)
key
- entry
- Copyright © 2009–2020 Waarp. All rights reserved.