Interface Cache<K,V>

All Known Subinterfaces:
LoadingCache<K,V>

public interface Cache<K,V>
A semi-persistent mapping from keys to values. Cache entries are manually added using #get(Object, Callable) or put(Object, Object), and are stored in the cache until either evicted or manually invalidated.

Implementations of this interface are expected to be thread-safe, and can be safely accessed by multiple concurrent threads.

Note that while this class is still annotated as Beta, the API is frozen from a consumer's standpoint. In other words existing methods are all considered non-Beta and won't be changed without going through an 18 month deprecation cycle; however new methods may be added at any time.

Since:
10.0
Author:
Charles Fry
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value associated with key in this cache, or null if there is no cached value for key.
    void
    put(K key, V value)
    Associates value with key in this cache.
  • Method Details

    • getIfPresent

      V getIfPresent(Object key)
      Returns the value associated with key in this cache, or null if there is no cached value for key.
      Since:
      11.0
    • put

      void put(K key, V value)
      Associates value with key in this cache. If the cache previously contained a value associated with key, the old value is replaced by value.

      Prefer #get(Object, Callable) when using the conventional "if cached, return; otherwise create, cache and return" pattern.

      Since:
      11.0