Package: grails.util

## [Java] Class CacheEntry<V>

- grails.util.CacheEntry

- 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.

  Authors:
    Lari Hotari
  Since:
    2.3.4

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `static class` | `CacheEntry.UpdateException` |

  - ### Constructor Summary

    Constructors
    Constructor and description
    `CacheEntry ()`
    `CacheEntry (V value)`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `void` | `expire()`
    `` | `long` | `getCreatedMillis()`
    `<K, V>` | `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>` | `static V` | `getValue(java.util.concurrent.ConcurrentMap<K, CacheEntry<V>> map, K key, long timeoutMillis, java.util.concurrent.Callable<V> updater)`
    `<K, V>` | `static V` | `getValue(java.util.concurrent.ConcurrentMap<K, CacheEntry<V>> map, K key, long timeoutMillis, java.util.concurrent.Callable<V> updater, boolean returnExpiredWhileUpdating)`
    `` | `V` | `getValue(long timeout, java.util.concurrent.Callable<V> updater)`
    `` | `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
    `` | `V` | `getValue()`
    `` | `protected V` | `getValueWhileUpdating(java.lang.Object cacheRequestObject)`
    `` | `protected boolean` | `hasExpired(long timeout, java.lang.Object cacheRequestObject)`
    `` | `boolean` | `isInitialized()`
    `` | `protected void` | `resetTimestamp(boolean updated)`
    `` | `void` | `setInitialized(boolean initialized)`
    `` | `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)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long, int), java.lang.Object#wait(long), 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()`

- - ### Constructor Detail

    - #### public CacheEntry()

    - #### public CacheEntry(V value)

  - ### Method Detail

    - #### public void expire()

    - #### public long getCreatedMillis()

    - #### <K, V> @java.lang.SuppressWarnings({ "unchecked", "rawtypes" }) 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. 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

      Parameters:
        `map` - the cache map
        `key` - the key to look up
        `timeoutMillis` - cache entry timeout
        `updater` - callback to create/update value
        `cacheEntryClass` - CacheEntry implementation class to use
        `returnExpiredWhileUpdating` - when true, return expired value while updating new value
        `cacheRequestObject` - context object that gets passed to hasExpired, shouldUpdate and updateValue methods, not used in default implementation
      Returns:

    - #### <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 updater is a callback for creating an updated value.

      Parameters:
        timeout
        updater
        returnExpiredWhileUpdating
        cacheRequestObject
      Returns:
        the current value

    - #### 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)