Interface SharedValueCache<K,V,S>

All Known Implementing Classes:
BasicSharedValueCache

public interface SharedValueCache<K,V,S>
Cache API where cached values are shared on a secondary key.

The idea for this API is for situations where it is desirable to cache a common value that is expensive to compute, but with potentially different expiration times for different uses. Thus the expensive value can be computed once using a "shared key" but then cached multiple times with different expiration times using a primary key.

  • Method Summary

    Modifier and Type
    Method
    Description
    get(K key)
    Get a cached value by key.
    void
    Prune shared values no longer in use.
    put(K key, S shareKey, Function<S,V> valueProvider, long ttl)
    Add a value to the cache.
  • Method Details

    • get

      V get(K key)
      Get a cached value by key.
      Parameters:
      key - the key of the value to get
      Returns:
      the value, or null if not available (or expired)
    • put

      V put(K key, S shareKey, Function<S,V> valueProvider, long ttl)
      Add a value to the cache.
      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

      void prune()
      Prune shared values no longer in use.