Interface MutableCacheEntry<K,​V>

  • All Superinterfaces:
    CacheEntry<K,​V>

    public interface MutableCacheEntry<K,​V>
    extends CacheEntry<K,​V>
    A mutable entry is used inside the EntryProcessor to perform updates and retrieve information from a cache entry.

    A mutation is only done if a method for mutation is called, e.g. setValue or remove. If multiple mutate methods are called in sequence only the last method will have an effect.

    One instance is only usable by a single thread and for one call of EntryProcessor.process(MutableCacheEntry).

    Author:
    Jens Wilke
    See Also:
    EntryProcessor
    • Method Detail

      • getValue

        V getValue()

        Returns the value to which the cache associated the key, or null if the cache contains no mapping for this key. null is also returned if this entry contains an exception.

        If the cache does permit null values, then a return value of null does not necessarily indicate that the cache contained no mapping for the key. It is also possible that the cache explicitly associated the key to the value null. Use exists() to check whether an entry is existing instead of a null check.

        If read through operation is enabled and the entry is not yet existing in the cache, the call to this method triggers a call to the cache loader.

        In contrast to the main cache interface there is no no peekValue method, since the same effect can be achieved by the combination of exists() and getValue().

        Specified by:
        getValue in interface CacheEntry<K,​V>
        Throws:
        RestartException - If the information is not yet available and the cache needs to do an asynchronous operation to supply it. After completion, the entry processor will be executed again.
        CacheLoaderException - if loading produced an exception
        See Also:
        CacheLoader
      • getException

        Throwable getException()
        The exception happened when the value was loaded and the exception could not be suppressed. null if no exception happened or it was suppressed. If null then getValue() returns a value and does not throw an exception.

        If a loader is present and the entry is not yet loaded or expired, a load is triggered.

        Specified by:
        getException in interface CacheEntry<K,​V>
      • exists

        boolean exists()
        True if a mapping exists in the cache, never invokes the loader / cache source.

        After this method returns true, a call to getValue will always return the cached value and never invoke the loader. The potential expiry of the value is only checked once and the return values of this method and getValue will be consistent.

        Throws:
        RestartException - If the information is not yet available and the cache needs to do an asynchronous operation to supply it. After completion, the entry processor will be executed again.
      • getOldValue

        V getOldValue()
        The current value in the cache. Identical to getValue(), but not modified after a mutation method is called. Intended for fluent operation.

        If read through operation is enabled and the entry is not yet existing in the cache, the call to this method triggers a call to the cache loader.

        Throws:
        RestartException - If the information is not yet available and the cache needs to do an asynchronous operation to supply it. After completion, the entry processor will be executed again.
      • wasExisting

        boolean wasExisting()
        True if a mapping exists in the cache, never invokes the loader / cache source. Identical to exists(), but not modified after a mutation method is called. Intended for fluent operation.
        Throws:
        RestartException - If the information is not yet available and the cache needs to do an asynchronous operation to supply it. After completion, the entry processor will be executed again.
      • setValue

        MutableCacheEntry<K,​V> setValue​(V v)
        Insert or updates the cache value assigned to this key. After calling this method exists will return true and getValue will return the set value.

        If a writer is registered, the CacheWriter.write(Object, Object) is called.

      • reload

        MutableCacheEntry<K,​V> reload()
        Calls the loader unconditionally in this operation. Multiple calls to reload have no effect.
      • setException

        MutableCacheEntry<K,​V> setException​(Throwable ex)
        Insert or update the entry and sets an exception. The exception will be propagated as CacheLoaderException.

        The effect depends on expiry and resilience setting. An exception will be kept in the cache only if there is an expiry configured or the resilience policy is allowing that.

        See Also:
        ResiliencePolicy
      • setExpiryTime

        MutableCacheEntry<K,​V> setExpiryTime​(long t)
        Set a new expiry time for the entry. If combined with setValue(V) the entry will be updated or inserted with this expiry time, otherwise just the expiry time will be updated.

        Special time values are defined and described at ExpiryTimeValues

        Parameters:
        t - Time in millis since epoch.
      • getRefreshedTime

        long getRefreshedTime()
        Timestamp of the last refresh of the cached value. This is the start time (before the loader was called) of a successful load operation, or the time the value was modified directly via Cache.put(K, V) or other sorts of mutation. Does not trigger a load.

        Rationale: We call it "refreshed" time since we don't know whether the value actually changed. If a load produces the same value as before the entry is refreshed but effectively not updated or modified. The past tense means its the time of the last refresh and is not the upcoming refresh.

      • setRefreshedTime

        MutableCacheEntry<K,​V> setRefreshedTime​(long t)
        If setValue(Object) is used, this sets an alternative refreshed time for expiry calculations. The entry refreshed time is not updated, if the entry is not mutated.

        If refresh ahead is enabled via Cache2kBuilder.refreshAhead(boolean), the next refresh time is controlled by the expiry time.