org.codehaus.groovy.grails.web.util
Class CacheEntry<T>
java.lang.Object
org.codehaus.groovy.grails.web.util.CacheEntry<T>
public class CacheEntry<T>
- 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.
|
Field Summary |
protected long |
createdMillis
|
protected java.util.concurrent.atomic.AtomicReference<T> |
valueRef
|
protected java.util.concurrent.locks.Lock |
writeLock
|
|
Method Summary |
void |
expire()
|
long |
getCreatedMillis()
|
T |
getValue()
|
T |
getValue(long timeout,
java.security.PrivilegedAction<T> updater)
gets the current value from the entry and updates it if it's older than timeout
updater is a callback for creating an updated value. |
protected boolean |
hasExpired(long timeout)
|
protected void |
resetTimestamp()
|
protected boolean |
shouldUpdate(long beforeLockingCreatedMillis)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
valueRef
protected java.util.concurrent.atomic.AtomicReference<T> valueRef
createdMillis
protected long createdMillis
writeLock
protected java.util.concurrent.locks.Lock writeLock
CacheEntry
public CacheEntry(T value)
getValue
public T getValue(long timeout,
java.security.PrivilegedAction<T> updater)
- gets the current value from the entry and updates it if it's older than timeout
updater is a callback for creating an updated value.
- Parameters:
timeout - updater -
- Returns:
getValue
public T getValue()
hasExpired
protected boolean hasExpired(long timeout)
shouldUpdate
protected boolean shouldUpdate(long beforeLockingCreatedMillis)
resetTimestamp
protected void resetTimestamp()
getCreatedMillis
public long getCreatedMillis()
expire
public void expire()