Package net.solarnetwork.central.support
Class BasicSharedValueCache<K,V,S>
java.lang.Object
net.solarnetwork.central.support.BasicSharedValueCache<K,V,S>
- All Implemented Interfaces:
SharedValueCache<K,V, S>
Basic implementation of
SharedValueCache using ConcurrentMap
objects for storage.-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.BasicSharedValueCache(ConcurrentMap<K, net.solarnetwork.util.CachedResult<V>> cache, ConcurrentMap<S, V> sharedCache) Constructor. -
Method Summary
-
Constructor Details
-
BasicSharedValueCache
public BasicSharedValueCache()Constructor. -
BasicSharedValueCache
public BasicSharedValueCache(ConcurrentMap<K, net.solarnetwork.util.CachedResult<V>> cache, ConcurrentMap<S, V> sharedCache) Constructor.- Parameters:
cache- the primary cachesharedCache- the shared cache
-
-
Method Details
-
get
Description copied from interface:SharedValueCacheGet a cached value by key.- Specified by:
getin interfaceSharedValueCache<K,V, S> - Parameters:
key- the key of the value to get- Returns:
- the value, or null if not available (or expired)
-
put
Description copied from interface:SharedValueCacheAdd a value to the cache.- Specified by:
putin interfaceSharedValueCache<K,V, S> - Parameters:
key- the cache keyshareKey- the shared value keyvalueProvider- the cache value providerttl- the cache value time to live, in seconds- Returns:
- the value, either a shared instance or newly computed by
valueProvider
-
prune
public void prune()Prune shared values no longer in use.- Specified by:
prunein interfaceSharedValueCache<K,V, S>
-