Package net.solarnetwork.central.support
Class SimpleCache<K,V>
java.lang.Object
net.solarnetwork.central.support.SimpleCache<K,V>
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterable<javax.cache.Cache.Entry<K,,V>> javax.cache.Cache<K,V>
A very loose and basic implementation of
Cache, using a
ConcurrentMap to store the data.
This class does not support any of the cache listener methods, configuration,
or the cache manager. Entries are not automatically released from memory, but
will not be returned once expired. The iterator() method will
release expired entries during iteration, so can be used to free memory as
needed.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface javax.cache.Cache
javax.cache.Cache.Entry<K,V> -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSimpleCache(String name) Constructor.SimpleCache(String name, ConcurrentMap<K, ? extends net.solarnetwork.util.CachedResult<V>> data) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()voidclose()booleancontainsKey(K key) voidderegisterCacheEntryListener(javax.cache.configuration.CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) getAndRemove(K key) getAndReplace(K key, V value) javax.cache.CacheManagergetConfiguration(Class<C> clazz) getName()Get the TTL time unit.longgetTtl()Get the time-to-live.<T> TinvokeAll(Set<? extends K> keys, javax.cache.processor.EntryProcessor<K, V, T> entryProcessor, Object... arguments) booleanisClosed()iterator()voidloadAll(Set<? extends K> keys, boolean replaceExistingValues, javax.cache.integration.CompletionListener completionListener) voidvoidbooleanputIfAbsent(K key, V value) voidregisterCacheEntryListener(javax.cache.configuration.CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) booleanbooleanvoidvoidbooleanbooleanvoidsetTimeUnit(TimeUnit timeUnit) Set the TTL time unit.voidsetTtl(long ttl) Set the time to live.<T> TMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
DEFAULT_TTL
public static final long DEFAULT_TTL- See Also:
-
DEFAULT_TIME_UNIT
-
-
Constructor Details
-
SimpleCache
Constructor.A
ConcurrentHashMapwill be used.- Parameters:
name- the name to use
-
SimpleCache
public SimpleCache(String name, ConcurrentMap<K, ? extends net.solarnetwork.util.CachedResult<V>> data) Constructor.- Parameters:
data- the map to use to store the cached data in- Throws:
IllegalArgumentException- if any argument is null
-
-
Method Details
-
get
-
getAll
-
containsKey
-
loadAll
-
put
-
getAndPut
-
putAll
-
putIfAbsent
-
remove
-
remove
-
getAndRemove
-
replace
-
replace
-
getAndReplace
-
removeAll
-
removeAll
public void removeAll() -
clear
public void clear() -
getConfiguration
-
invoke
-
invokeAll
-
getName
-
getCacheManager
public javax.cache.CacheManager getCacheManager() -
close
public void close() -
isClosed
public boolean isClosed() -
unwrap
-
registerCacheEntryListener
-
deregisterCacheEntryListener
-
iterator
-
getTtl
public long getTtl()Get the time-to-live.- Returns:
- the time to live
-
setTtl
public void setTtl(long ttl) Set the time to live.- Parameters:
ttl- the time to live to set
-
getTimeUnit
Get the TTL time unit.- Returns:
- the TTL time unit
-
setTimeUnit
Set the TTL time unit.- Parameters:
timeUnit- the TTL time unit to set
-