Interface CacheEntryUpdate<T>

Type Parameters:
T - the cache value type
All Superinterfaces:
Serializable
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface CacheEntryUpdate<T> extends Serializable
A change to one cache entry, made atomically by CacheMap.update(String, CacheEntryUpdate) and CacheMap.updateAll(java.util.Collection, CacheEntryUpdate).

Given the entry's current value, or null when the key has none, it returns the value to store, or null to leave the entry as it is. Deciding on the current value rather than comparing it with an expected one keeps the change atomic whatever form a cache stores its values in (objects, serialized bytes, JSON).

A clustered cache runs the update where the entry lives, possibly on another node, and may run it again on a backup copy of the entry. An implementation must therefore be serializable, deterministic and free of side effects, and must not modify the value it is given (return a copy). Prefer a named class to a lambda: serialized lambdas tie the nodes to the exact same build of the class declaring them.

  • Method Summary

    Modifier and Type
    Method
    Description
    apply(T current)
    Computes the new value of an entry.
  • Method Details

    • apply

      T apply(T current)
      Computes the new value of an entry.
      Parameters:
      current - the current value, or null if none
      Returns:
      the value to store, or null to leave it unchanged