Class ShinyCache<Key,Value>

java.lang.Object
org.flasby.util.ShinyCache<Key,Value>
All Implemented Interfaces:
BlockingCache<Key,Value>, Cache<Key,Value>

public abstract class ShinyCache<Key,Value> extends Object implements BlockingCache<Key,Value>
is a cache which handles entry expiry and will ensure that multiple simultaneous requests using the same key will only make a single request to get the missing value. Simultaneous requests will be queued until the value is returned. Cached entries may have a NULL value.
Author:
Steve Flasby 21 Sep 2012
  • Constructor Details

    • ShinyCache

      public ShinyCache()
      simple, ever growing, cache
    • ShinyCache

      public ShinyCache(org.flasby.util.ShinyCache.ExpiryPolicy expiryPolicy)
      cache which expires entries after a fixed lifetime.
      Parameters:
      expiryPolicy -
    • ShinyCache

      public ShinyCache(int capacity, ShinyCache.EvictionPolicy evictionPolicy)
    • ShinyCache

      public ShinyCache(org.flasby.util.ShinyCache.ExpiryPolicy expiryPolicy, int capacity, ShinyCache.EvictionPolicy evictionPolicy)
  • Method Details

    • never

      public static org.flasby.util.ShinyCache.ExpiryPolicy never()
    • expireAfterMillis

      public static org.flasby.util.ShinyCache.ExpiryPolicy expireAfterMillis(long periodInMillis)
    • get

      public Value get(Key key)
      gets the key form the cache or returns NULL if the Thread was interrupted.
      Specified by:
      get in interface Cache<Key,Value>
    • getAndWait

      public Value getAndWait(Key key) throws InterruptedException
      Description copied from interface: BlockingCache
      attempts to get a value from the Cache. If a previous request to populate the cache with the value for this key is in progress, then the current thread should block until the cache is populated.
      Specified by:
      getAndWait in interface BlockingCache<Key,Value>
      Parameters:
      key -
      Returns:
      Throws:
      InterruptedException
    • getAndWait

      public Value getAndWait(Key key, long maxWaitMillis) throws InterruptedException
      Description copied from interface: BlockingCache
      attempt to get a value from the cache. If a previous request to populate the cache with the value for this key is in progress, then the current thread will block for at most maxWaitMillis until the cache is populated. Should no value become available within this maxWait time then the cache will return null.
      Specified by:
      getAndWait in interface BlockingCache<Key,Value>
      Parameters:
      key -
      maxWaitMillis -
      Returns:
      Throws:
      InterruptedException
    • size

      public int size()
      Specified by:
      size in interface Cache<Key,Value>
    • iterator

      public Iterator<Value> iterator()
      Specified by:
      iterator in interface Cache<Key,Value>