public class CacheEntry<V> extends java.lang.Object
Wrapper for a value inside a cache that adds timestamp information for expiration and prevents "cache storms" with a Lock. JMM happens-before is ensured with AtomicReference. Objects in cache are assumed to not change after publication.
Modifiers | Name | Description |
---|---|---|
static class |
CacheEntry.UpdateException |
Constructor and description |
---|
CacheEntry
() |
CacheEntry
(V value) |
Type Params | Return Type | Name and description |
---|---|---|
|
public CacheEntry |
call() |
|
public void |
expire() |
|
public long |
getCreatedMillis() |
<K, V> |
public static V |
getValue(java.util.concurrent.ConcurrentMap<K, CacheEntry<V>> map, K key, long timeoutMillis, java.util.concurrent.Callable<V> updater, java.util.concurrent.Callable<? extends CacheEntry> cacheEntryFactory, boolean returnExpiredWhileUpdating, java.lang.Object cacheRequestObject) Gets a value from cache. |
<K, V> |
public static V |
getValue(java.util.concurrent.ConcurrentMap<K, CacheEntry<V>> map, K key, long timeoutMillis, java.util.concurrent.Callable<V> updater) |
<K, V> |
public static V |
getValue(java.util.concurrent.ConcurrentMap<K, CacheEntry<V>> map, K key, long timeoutMillis, java.util.concurrent.Callable<V> updater, boolean returnExpiredWhileUpdating) |
|
public V |
getValue(long timeout, java.util.concurrent.Callable<V> updater) |
|
public V |
getValue(long timeout, java.util.concurrent.Callable<V> updater, boolean returnExpiredWhileUpdating, java.lang.Object cacheRequestObject) gets the current value from the entry and updates it if it's older than timeout |
|
public V |
getValue() |
|
protected V |
getValueWhileUpdating(java.lang.Object cacheRequestObject) |
|
protected boolean |
hasExpired(long timeout, java.lang.Object cacheRequestObject) |
|
public boolean |
isInitialized() |
|
protected void |
resetTimestamp(boolean updated) |
|
public void |
setInitialized(boolean initialized) |
|
public void |
setValue(V val) |
|
protected boolean |
shouldUpdate(long beforeLockingCreatedMillis, java.lang.Object cacheRequestObject) |
|
protected V |
updateValue(V oldValue, java.util.concurrent.Callable<V> updater, java.lang.Object cacheRequestObject) |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Gets a value from cache. If the key doesn't exist, it will create the value using the updater callback Prevents cache storms with a lock The key is always added to the cache. Null return values will also be cached. You can use this together with ConcurrentLinkedHashMap to create a bounded LRU cache
map
- the cache mapkey
- the key to look uptimeoutMillis
- cache entry timeoutupdater
- callback to create/update valuecacheEntryClass
- CacheEntry implementation class to usereturnExpiredWhileUpdating
- when true, return expired value while updating new valuecacheRequestObject
- context object that gets passed to hasExpired, shouldUpdate and updateValue methods, not used in default implementationgets the current value from the entry and updates it if it's older than timeout updater is a callback for creating an updated value.