Class GuavaCache<K,V>
java.lang.Object
org.ametys.plugins.core.impl.cache.GuavaCache<K,V>
- Type Parameters:
K
- the keyV
- the value
- All Implemented Interfaces:
Cache<K,
V>
Implementation of AmetysCache with Guava library
-
Field Summary
Modifier and TypeFieldDescriptionthe cache itself, using Guava implementationprotected boolean
True if the size of the cache can be computed, false otherwise (e.g., the cache store a component)protected I18nizableText
Description of the cacheprotected Duration
The length of time after an entry is created that it should be automaticallyprotected String
Id of the cacheprotected boolean
True if the cache can be transmitted in sub-requests of DispatchGenerator, false otherwises.protected boolean
True if the put or putAll have been called (even without values), false otherwises.protected I18nizableText
Label of the cacheprotected long
Maximum size of the cache in bytes -
Constructor Summary
ConstructorDescriptionGuavaCache
(String id, I18nizableText label, I18nizableText description, long size, boolean computableSize, Duration duration, boolean isDispatchable) Implementation of AmetysCache with Guava library -
Method Summary
Modifier and TypeMethodDescriptionasMap()
Get the cache as a simple MapReturns the value associated withkey
in this cache if it existReturns the value associated withkey
in this cache if it exist, obtaining that value from given function if necessary and store it.getAll
(AbstractCacheKey filterKey) Get the cache as a simple Map, filtered by filled values of the cache keyGet all statistics about cacheGet the description of cachegetId()
Get the id of cachegetLabel()
Get the label of cachelong
Get the max size allocated to the cache, in bytes.long
Get the size the cache take in byteslong
Get the number of values in cacheboolean
return true if key is present in cachevoid
invalidate
(K key) Discards any cached value for keykey
.void
Discards all entries in the cache, without reseting statisticsboolean
Is this cache size computableboolean
Can the cache be transmitted in sub-requests of DispatchGeneratorboolean
Is this cache filled at least once.void
Associatesvalue
withkey
in this cache.void
Copies all of the mappings from the specified map to the cache.void
Create or reset the whole cache (including statistics).
The CACHE_RESET event is not notified by this method, but should be by callers.
-
Field Details
-
_cache
the cache itself, using Guava implementation -
_id
Id of the cache -
_label
Label of the cache -
_description
Description of the cache -
_size
Maximum size of the cache in bytes -
_computableSize
True if the size of the cache can be computed, false otherwise (e.g., the cache store a component) -
_duration
The length of time after an entry is created that it should be automatically -
_isInitialized
True if the put or putAll have been called (even without values), false otherwises. become false again when the cache is reseted or if all values have been cleaned. -
_isDispatchable
True if the cache can be transmitted in sub-requests of DispatchGenerator, false otherwises.
-
-
Constructor Details
-
GuavaCache
public GuavaCache(String id, I18nizableText label, I18nizableText description, long size, boolean computableSize, Duration duration, boolean isDispatchable) Implementation of AmetysCache with Guava library- Parameters:
id
- id of the cachelabel
- label of the cachedescription
- descriptionsize
- maximum size of the cachecomputableSize
- true if the size of the cache can be computedduration
- the length of time after an entry is created that it should be automatically removedisDispatchable
- true if the cache can be transmitted in sub-requests of DispatchGenerator
-
-
Method Details
-
resetCache
Description copied from interface:Cache
Create or reset the whole cache (including statistics).
The CACHE_RESET event is not notified by this method, but should be by callers.- Specified by:
resetCache
in interfaceCache<K,
V>
-
get
Description copied from interface:Cache
Returns the value associated withkey
in this cache if it exist, obtaining that value from given function if necessary and store it.- Specified by:
get
in interfaceCache<K,
V> - 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
Description copied from interface:Cache
Returns the value associated withkey
in this cache if it exist -
put
Description copied from interface:Cache
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. -
putAll
Description copied from interface:Cache
Copies all of the mappings from the specified map to the cache. -
getCacheStats
Description copied from interface:Cache
Get all statistics about cache- Specified by:
getCacheStats
in interfaceCache<K,
V> - Returns:
- statistic about the cache (hit, miss, evictions...)
-
getMemorySize
Description copied from interface:Cache
Get the size the cache take in bytes- Specified by:
getMemorySize
in interfaceCache<K,
V> - Returns:
- the size of the cache if it's computable, return 0 otherwise
- Throws:
CacheException
- throw CacheException if memory size can not be computed
-
getNumberOfElements
Description copied from interface:Cache
Get the number of values in cache- Specified by:
getNumberOfElements
in interfaceCache<K,
V> - Returns:
- the number of values in cache
-
invalidate
Description copied from interface:Cache
Discards any cached value for keykey
.- Specified by:
invalidate
in interfaceCache<K,
V> - Parameters:
key
- the key to invalidate
-
invalidateAll
Description copied from interface:Cache
Discards all entries in the cache, without reseting statistics- Specified by:
invalidateAll
in interfaceCache<K,
V>
-
getDescription
Description copied from interface:Cache
Get the description of cache- Specified by:
getDescription
in interfaceCache<K,
V> - Returns:
- the description of cache
-
getLabel
Description copied from interface:Cache
Get the label of cache -
getId
Description copied from interface:Cache
Get the id of cache -
getMaxSize
Description copied from interface:Cache
Get the max size allocated to the cache, in bytes. This value can be set to Long.MAX_VALUE for infinite cache- Specified by:
getMaxSize
in interfaceCache<K,
V> - Returns:
- the max size allocated to the cache
-
hasKey
Description copied from interface:Cache
return true if key is present in cache -
asMap
Description copied from interface:Cache
Get the cache as a simple Map -
isComputableSize
Description copied from interface:Cache
Is this cache size computable- Specified by:
isComputableSize
in interfaceCache<K,
V> - Returns:
- true if the cache size is computable
-
isInitialized
Description copied from interface:Cache
Is this cache filled at least once.- Specified by:
isInitialized
in interfaceCache<K,
V> - Returns:
- true if the cache have been filled (put or putAll have been called even without values), false when the cache is new, reseted or if all values have been cleaned
-
isDispatchable
Description copied from interface:Cache
Can the cache be transmitted in sub-requests of DispatchGenerator- Specified by:
isDispatchable
in interfaceCache<K,
V> - Returns:
- true if the cache can be transmitted in sub-requests of DispatchGenerator
-
getAll
Description copied from interface:Cache
Get the cache as a simple Map, filtered by filled values of the cache key
-