Interface Cache

All Known Implementing Classes:
AbstractCacheAdapter, EhCacheAdapter, JCacheAdapter, NoCache, WeakReferenceCache

public interface Cache
Abstraction for a Caching mechanism. All Axon component rely on this abstraction, so that different providers can be plugged in. In future versions, this abstraction may be replaced with the javax.cache api, as soon as that api is final.
Since:
2.1.2
Author:
Allard Buijze
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Interface describing callback methods, which are invoked when changes are made in the underlying cache.
    static class 
    Adapter implementation for the EntryListener, allowing for overriding only specific callback methods.
  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> T
    computeIfAbsent(Object key, Supplier<T> valueSupplier)
    Returns the value under the given key in the cache.
    default <V> void
    Perform the update in the value behind the given key.
    boolean
    Indicates whether there is an item stored under given key.
    <K, V> V
    get(K key)
    Returns an item from the cache, or null if no item was stored under that key
    void
    put(Object key, Object value)
    Stores the given value in the cache, under given key.
    boolean
    putIfAbsent(Object key, Object value)
    Stores the given value in the cache, under given key, if no element is yet available under that key.
    Registers the given cacheEntryListener to listen for Cache changes.
    boolean
    Removes the entry stored under given key.
    default void
    Remove all stored entries in this cache.
  • Method Details

    • get

      <K, V> V get(K key)
      Returns an item from the cache, or null if no item was stored under that key
      Type Parameters:
      K - The type of key used
      V - The type of value stored
      Parameters:
      key - The key under which the item was cached
      Returns:
      the item stored under the given key
    • put

      void put(Object key, Object value)
      Stores the given value in the cache, under given key. If an item already exists, it is updated with the new value.
      Parameters:
      key - The key under which to store the item
      value - The item to cache
    • putIfAbsent

      boolean putIfAbsent(Object key, Object value)
      Stores the given value in the cache, under given key, if no element is yet available under that key. This operation is performed atomically.
      Parameters:
      key - The key under which to store the item
      value - The item to cache
      Returns:
      true if no value was previously assigned to the key, false otherwise.
    • computeIfAbsent

      default <T> T computeIfAbsent(Object key, Supplier<T> valueSupplier)
      Returns the value under the given key in the cache. If there is no value present, will invoke the given valueSupplier, put the value in the cache and return the produced value.
      Parameters:
      key - The key under which the item was cached. If not present, this key is used to cache the outcome of the valueSupplier.
      valueSupplier - A supplier that lazily supplies the value if there's no key present.
      Returns:
      The value that is in the cache after the operation. This can be the original value or the one supplied by the valueSupplier.
    • remove

      boolean remove(Object key)
      Removes the entry stored under given key. If no such entry exists, nothing happens.
      Parameters:
      key - The key under which the item was stored
      Returns:
      true if a value was previously assigned to the key and has been removed, false otherwise.
    • removeAll

      default void removeAll()
      Remove all stored entries in this cache.
    • containsKey

      boolean containsKey(Object key)
      Indicates whether there is an item stored under given key.
      Parameters:
      key - The key to check
      Returns:
      true if an item is available under that key, false otherwise.
    • registerCacheEntryListener

      Registration registerCacheEntryListener(Cache.EntryListener cacheEntryListener)
      Registers the given cacheEntryListener to listen for Cache changes.
      Parameters:
      cacheEntryListener - The listener to register
      Returns:
      a handle to deregister the listener
    • computeIfPresent

      default <V> void computeIfPresent(Object key, UnaryOperator<V> update)
      Perform the update in the value behind the given key. The update is only executed if there's an entry referencing the key.
      Type Parameters:
      V - The type of the value to execute the update for.
      Parameters:
      key - The key to perform an update for, if not empty.
      update - The update to perform if the key is present.