Package org.ametys.core.cache
Interface Cache<K,V>
- 
- Type Parameters:
- K- the type of the keys in cache
- V- 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 SummaryAll Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Map<K,V>asMap()Get the cache as a simple MapVget(K key)Returns the value associated withkeyin this cache if it existVget(K key, Function<K,V> function)Returns the value associated withkeyin this cache if it exist, obtaining that value from given function if necessary and store it.CacheStatsgetCacheStats()Get all statistics about cacheI18nizableTextgetDescription()Get the description of cacheStringgetId()Get the id of cacheI18nizableTextgetLabel()Get the label of cachelonggetMaxSize()Get the max size allocated to the cache, in bytes.longgetMemorySize()Get the size the cache take in byteslonggetNumberOfElements()Get the number of values in cachebooleanhasKey(K key)return true if key is present in cachevoidinvalidate(K key)Discards any cached value for keykey.voidinvalidateAll()Discards all entries in the cache, without reseting statisticsbooleanisComputableSize()Is this cache size computablevoidput(K key, V value)Associatesvaluewithkeyin this cache.voidputAll(Map<K,V> map)Copies all of the mappings from the specified map to the cache.voidresetCache()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- 
getV get(K key, Function<K,V> function) throws CacheException Returns the value associated withkeyin this cache if it exist, obtaining that value from given function if necessary and store it.- Parameters:
- key- the key to get the element
- function- 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
 
 - 
getV get(K key) Returns the value associated withkeyin this cache if it exist- Parameters:
- key- the key to get the element
- Returns:
- V the value linked to key
 
 - 
putvoid put(K key, V value) Associatesvaluewithkeyin this cache. If the cache previously contained a value associated withkey, the old value is replaced byvalue. Thekeycan not be null.- Parameters:
- key- the key to get the element
- value- the value associated with key
 
 - 
putAllvoid 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
 
 - 
hasKeyboolean 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
 
 - 
invalidatevoid invalidate(K key) Discards any cached value for keykey.- Parameters:
- key- the key to invalidate
 
 - 
invalidateAllvoid invalidateAll() Discards all entries in the cache, without reseting statistics
 - 
resetCachevoid resetCache() Create or reset the whole cache (including statistics)
 - 
getCacheStatsCacheStats getCacheStats() Get all statistics about cache- Returns:
- statistic about the cache (hit, miss, evictions...)
 
 - 
getMemorySizelong 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
 
 - 
getMaxSizelong 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
 
 - 
getNumberOfElementslong getNumberOfElements() Get the number of values in cache- Returns:
- the number of values in cache
 
 - 
getLabelI18nizableText getLabel() Get the label of cache- Returns:
- the label of cache
 
 - 
getDescriptionI18nizableText getDescription() Get the description of cache- Returns:
- the description of cache
 
 - 
isComputableSizeboolean isComputableSize() Is this cache size computable- Returns:
- true if the cache size is computable
 
 
- 
 
-