Package org.flasby.util
Class ShinyCache<Key,Value>
java.lang.Object
org.flasby.util.ShinyCache<Key,Value>
- All Implemented Interfaces:
BlockingCache<Key,
,Value> Cache<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
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionsimple, ever growing, cacheShinyCache
(int capacity, ShinyCache.EvictionPolicy evictionPolicy) ShinyCache
(org.flasby.util.ShinyCache.ExpiryPolicy expiryPolicy) cache which expires entries after a fixed lifetime.ShinyCache
(org.flasby.util.ShinyCache.ExpiryPolicy expiryPolicy, int capacity, ShinyCache.EvictionPolicy evictionPolicy) -
Method Summary
Modifier and TypeMethodDescriptionstatic org.flasby.util.ShinyCache.ExpiryPolicy
expireAfterMillis
(long periodInMillis) gets the key form the cache or returns NULL if the Thread was interrupted.getAndWait
(Key key) attempts to get a value from the Cache.getAndWait
(Key key, long maxWaitMillis) attempt to get a value from the cache.iterator()
static org.flasby.util.ShinyCache.ExpiryPolicy
never()
int
size()
-
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
-
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
gets the key form the cache or returns NULL if the Thread was interrupted. -
getAndWait
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 interfaceBlockingCache<Key,
Value> - Parameters:
key
-- Returns:
- Throws:
InterruptedException
-
getAndWait
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 interfaceBlockingCache<Key,
Value> - Parameters:
key
-maxWaitMillis
-- Returns:
- Throws:
InterruptedException
-
size
public int size() -
iterator
-