Interface Cache<K,V>

Type Parameters:
K - type of cache keys
V - type of cached values
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 Cache<K,V>
Simple cache interface. No-op implementation (the one which never performs any caching) is considered correct.
API note
currently java-commons does not implement its own functional cache, it simply provides a universal interface and wrappers for known implementations
  • Method Summary

    Modifier and Type
    Method
    Description
    get(K key, @NonNull Function<? super K,? extends V> mappingFunction)
    Gets the value from the cache computing it on demand using the provided function.
    static <K, V> @NotNull Cache<K,V>
    Creates a cache which actually never performs caching.
  • Method Details

    • get

      V get(@NonNull K key, @NonNull @NonNull Function<? super K,? extends V> mappingFunction)
      Gets the value from the cache computing it on demand using the provided function.
      Parameters:
      key - key by which ti get the value from cache
      mappingFunction - function used to create the value if there is no cached one
      Returns:
      the current value associated with the specified key
      Throws:
      NullPointerException - if key is null
      NullPointerException - if mappingFunction is null
    • never

      @NotNull static <K, V> @NotNull Cache<K,V> never()
      Creates a cache which actually never performs caching.
      Type Parameters:
      K - type of cache keys
      V - type of cached values
      Returns:
      cache which actually never performs caching