Class BasicSharedValueCache<K,V,S>

java.lang.Object
net.solarnetwork.central.support.BasicSharedValueCache<K,V,S>
All Implemented Interfaces:
SharedValueCache<K,V,S>

public class BasicSharedValueCache<K,V,S> extends Object implements SharedValueCache<K,V,S>
Basic implementation of SharedValueCache using ConcurrentMap objects for storage.
  • 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 cache
      sharedCache - the shared cache
  • Method Details

    • get

      public V get(K key)
      Description copied from interface: SharedValueCache
      Get a cached value by key.
      Specified by:
      get in interface SharedValueCache<K,V,S>
      Parameters:
      key - the key of the value to get
      Returns:
      the value, or null if not available (or expired)
    • put

      public V put(K key, S shareKey, Function<S,V> valueProvider, long ttl)
      Description copied from interface: SharedValueCache
      Add a value to the cache.
      Specified by:
      put in interface SharedValueCache<K,V,S>
      Parameters:
      key - the cache key
      shareKey - the shared value key
      valueProvider - the cache value provider
      ttl - 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:
      prune in interface SharedValueCache<K,V,S>