Package fr.gouv.vitam.common.lru
Interface InterfaceLruCache<K,V>
-
- Type Parameters:
K
- KeyV
- Value
- All Known Implementing Classes:
SynchronizedLruCache
public interface InterfaceLruCache<K,V>
LRU cache interface. author Damian Momot
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clear()
Removes all entries from cacheboolean
contains(K key)
Checks whether cache contains valid entry for keyint
forceClearOldest()
Removes all oldest entries from cache (ttl based)V
get(K key)
Returns value cached with key.V
get(K key, java.util.concurrent.Callable<V> callback)
Tries to get element from cache.V
get(K key, java.util.concurrent.Callable<V> callback, long ttl)
Tries to get element from cache.int
getCapacity()
Returns cache capacitylong
getTtl()
Returns cache TTLboolean
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 TTLV
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
-
-
-
Method Detail
-
clear
void clear()
Removes all entries from cache
-
forceClearOldest
int forceClearOldest()
Removes all oldest entries from cache (ttl based)- Returns:
- the number of removed entries
-
contains
boolean contains(K key)
Checks whether cache contains valid entry for key- Parameters:
key
-- Returns:
- true if cache contains key and entry is valid
-
get
V get(K key)
Returns value cached with key.- Parameters:
key
-- Returns:
- value or null if key doesn't exist or entry is not valid
-
get
V get(K key, java.util.concurrent.Callable<V> callback) throws VitamException
Tries to get element from cache. If get fails callback is used to create element and returned value is stored in cache. Default TTL is used- Parameters:
key
-callback
-- Returns:
- Value
- Throws:
VitamException
java.lang.Exception
- if callback throws exception
-
get
V get(K key, java.util.concurrent.Callable<V> callback, long ttl) throws VitamException
Tries to get element from cache. If get fails callback is used to create element and returned value is stored in cache- Parameters:
key
-callback
-ttl
- time to live in milliseconds- Returns:
- Value
- Throws:
VitamException
java.lang.Exception
- if callback throws exception
-
getCapacity
int getCapacity()
Returns cache capacity- Returns:
- capacity of cache
-
size
int size()
Returns number of entries stored in cache (including invalid ones)- Returns:
- number of entries
-
getTtl
long getTtl()
Returns cache TTL- Returns:
- ttl in milliseconds
-
setNewTtl
void setNewTtl(long ttl)
Set a new TTL (for newly set objects only, not changing old values).- Parameters:
ttl
-
-
isEmpty
boolean isEmpty()
Checks whether cache is empty. If any entry exists (including invalid one) this method will return true- Returns:
- true if no entries are stored in cache
-
put
void put(K key, V value)
Puts value under key into cache. Default TTL is used- Parameters:
key
-value
-
-
put
void put(K key, V value, long ttl)
Puts value under key into cache with desired TTL- Parameters:
key
-value
-ttl
- time to live in milliseconds
-
remove
V remove(K key)
Removes entry from cache (if exists)- Parameters:
key
-- Returns:
- the value if it still exists
-
updateTtl
void updateTtl(K key)
Update the TTL of the associated object if it still exists- Parameters:
key
-
-
-