K
- KeyV
- Valuepublic class SynchronizedLruCache<K,V> extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_INITIAL_CAPACITY
Initial capacity
|
static float |
DEFAULT_LOAD_FACTOR
Load factor
|
Constructor and Description |
---|
SynchronizedLruCache(int capacity,
long ttl)
Creates new SynchronizedLruCache with DEFAULT_LOAD_FACTOR and DEFAULT_INITIAL_CAPACITY
|
SynchronizedLruCache(int capacity,
long ttl,
int initialCapacity)
Creates new SynchronizedLruCache with DEFAULT_LOAD_FACTOR
|
SynchronizedLruCache(int capacity,
long ttl,
int initialCapacity,
float loadFactor)
Creates new SynchronizedLruCache
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all entries from cache
|
boolean |
contains(K key)
Checks whether cache contains valid entry for key
|
protected InterfaceLruCacheEntry<V> |
createEntry(V value,
long ttl)
Creates new LruCacheEntry
|
int |
forceClearOldest()
Removes all oldest entries from cache (ttl based)
|
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.
|
int |
getCapacity()
Returns cache capacity
|
protected 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 void |
putEntry(K key,
InterfaceLruCacheEntry<V> entry)
Puts entry into cache
|
V |
remove(K key)
Removes entry from cache (if exists)
|
void |
setNewTtl(long ttl)
Set a new TTL (for newly set objects only, not changing old values).
|
int |
size()
Returns number of entries stored in cache (including invalid ones)
|
void |
updateTtl(K key)
Update the TTL of the associated object if it still exists
|
public static final int DEFAULT_INITIAL_CAPACITY
public static final float DEFAULT_LOAD_FACTOR
public SynchronizedLruCache(int capacity, long ttl, int initialCapacity, float loadFactor)
capacity
- max cache capacityttl
- time to live in millisecondsinitialCapacity
- initial cache capacityloadFactor
- public SynchronizedLruCache(int capacity, long ttl, int initialCapacity)
capacity
- max cache capacityttl
- time to live in millisecondsinitialCapacity
- initial cache capacitypublic SynchronizedLruCache(int capacity, long ttl)
capacity
- max cache capacityttl
- time to live in millisecondspublic void clear()
InterfaceLruCache
public V get(K key)
InterfaceLruCache
get
in interface InterfaceLruCache<K,V>
public int getCapacity()
InterfaceLruCache
protected InterfaceLruCacheEntry<V> getEntry(K key)
public int size()
InterfaceLruCache
public void put(K key, V value, long ttl)
InterfaceLruCache
put
in interface InterfaceLruCache<K,V>
ttl
- time to live in millisecondsprotected void putEntry(K key, InterfaceLruCacheEntry<V> entry)
public V remove(K key)
InterfaceLruCache
public int forceClearOldest()
InterfaceLruCache
public boolean contains(K key)
InterfaceLruCache
contains
in interface InterfaceLruCache<K,V>
protected InterfaceLruCacheEntry<V> createEntry(V value, long ttl)
value
- ttl
- public V get(K key, Callable<V> callback) throws VitamException
InterfaceLruCache
get
in interface InterfaceLruCache<K,V>
VitamException
public V get(K key, Callable<V> callback, long ttl) throws VitamException
InterfaceLruCache
get
in interface InterfaceLruCache<K,V>
ttl
- time to live in millisecondsVitamException
public long getTtl()
InterfaceLruCache
getTtl
in interface InterfaceLruCache<K,V>
public void setNewTtl(long ttl)
InterfaceLruCache
setNewTtl
in interface InterfaceLruCache<K,V>
public void updateTtl(K key)
InterfaceLruCache
updateTtl
in interface InterfaceLruCache<K,V>
protected V getValue(K key)
key
- public boolean isEmpty()
InterfaceLruCache
isEmpty
in interface InterfaceLruCache<K,V>
public void put(K key, V value)
InterfaceLruCache
put
in interface InterfaceLruCache<K,V>
Copyright © 2018 Vitam. All rights reserved.