Package org.ametys.core.cache
Interface Cache<K,V>
-
- Type Parameters:
K
- the type of the keys in cacheV
- the type of the values in cache
- All Known Implementing Classes:
GuavaCache
public interface Cache<K,V>
A cache represents a store of objects indexed with a key
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Map<K,V>
asMap()
Get the cache as a simple MapV
get(K key)
Returns the value associated withkey
in this cache if it existV
get(K key, Function<K,V> function)
Returns the value associated withkey
in this cache if it exist, obtaining that value from given function if necessary and store it.CacheStats
getCacheStats()
Get all statistics about cacheI18nizableText
getDescription()
Get the description of cacheString
getId()
Get the id of cacheI18nizableText
getLabel()
Get the label of cachelong
getMaxSize()
Get the max size allocated to the cache, in bytes.long
getMemorySize()
Get the size the cache take in byteslong
getNumberOfElements()
Get the number of values in cacheboolean
hasKey(K key)
return true if key is present in cachevoid
invalidate(K key)
Discards any cached value for keykey
.void
invalidateAll()
Discards all entries in the cache, without reseting statisticsboolean
isComputableSize()
Is this cache size computablevoid
put(K key, V value)
Associatesvalue
withkey
in this cache.void
putAll(Map<K,V> map)
Copies all of the mappings from the specified map to the cache.void
resetCache()
Create or reset the whole cache (including statistics)default Map<String,Object>
toJSONMap(org.slf4j.Logger logger)
Get the definition in JSON Map
-
-
-
Method Detail
-
get
V get(K key, Function<K,V> function) throws CacheException
Returns the value associated withkey
in this cache if it exist, obtaining that value from given function if necessary and store it.- Parameters:
key
- the key to get the elementfunction
- the function to compute the value if key is not present- Returns:
- V the value associated with key
- Throws:
CacheException
- throw CacheException if the key is null or invalid, or if failed to compute the new value
-
get
V get(K key)
Returns the value associated withkey
in this cache if it exist- Parameters:
key
- the key to get the element- Returns:
- V the value linked to key
-
put
void put(K key, V value)
Associatesvalue
withkey
in this cache. If the cache previously contained a value associated withkey
, the old value is replaced byvalue
. Thekey
can not be null.- Parameters:
key
- the key to get the elementvalue
- the value associated with key
-
putAll
void putAll(Map<K,V> map)
Copies all of the mappings from the specified map to the cache.- Parameters:
map
- map of key/values to be stored in the cache
-
hasKey
boolean hasKey(K key)
return true if key is present in cache- Parameters:
key
- the key to be checked- Returns:
- true if key is present in cache
-
invalidate
void invalidate(K key)
Discards any cached value for keykey
.- Parameters:
key
- the key to invalidate
-
invalidateAll
void invalidateAll()
Discards all entries in the cache, without reseting statistics
-
resetCache
void resetCache()
Create or reset the whole cache (including statistics)
-
getCacheStats
CacheStats getCacheStats()
Get all statistics about cache- Returns:
- statistic about the cache (hit, miss, evictions...)
-
getMemorySize
long getMemorySize() throws CacheException
Get the size the cache take in bytes- Returns:
- the size of the cache if it's computable, return 0 otherwise
- Throws:
CacheException
- throw CacheException if memory size can not be computed
-
getMaxSize
long getMaxSize()
Get the max size allocated to the cache, in bytes. This value can be set to Long.MAX_VALUE for infinite cache- Returns:
- the max size allocated to the cache
-
getNumberOfElements
long getNumberOfElements()
Get the number of values in cache- Returns:
- the number of values in cache
-
getLabel
I18nizableText getLabel()
Get the label of cache- Returns:
- the label of cache
-
getDescription
I18nizableText getDescription()
Get the description of cache- Returns:
- the description of cache
-
isComputableSize
boolean isComputableSize()
Is this cache size computable- Returns:
- true if the cache size is computable
-
-