Class AbstractCache<K,​V>

java.lang.Object
io.github.xanthic.cache.core.AbstractCache<K,​V>
Type Parameters:
K - The type of keys that form the cache
V - The type of values contained in the cache
All Implemented Interfaces:
io.github.xanthic.cache.api.Cache<K,​V>

public abstract class AbstractCache<K,​V>
extends java.lang.Object
implements io.github.xanthic.cache.api.Cache<K,​V>
Provides a common implementation of:
  • Cache.computeIfAbsent(Object, Function)
  • Cache.putIfAbsent(Object, Object)
  • Cache.merge(Object, Object, BiFunction)

Subclasses ought to employ the same degree of locking for correctness.

Avoid this abstraction if the backing cache provider already provides an implementation for these methods.

Does not support null values.

  • Constructor Summary

    Constructors 
    Constructor Description
    AbstractCache()  
  • Method Summary

    Modifier and Type Method Description
    V compute​(K key, @NotNull java.util.function.BiFunction<? super K,​? super V,​? extends V> computeFunc)  
    V computeIfAbsent​(K key, @NotNull java.util.function.Function<K,​V> computeFunc)  
    V computeIfPresent​(K key, @NotNull java.util.function.BiFunction<? super K,​? super V,​? extends V> computeFunc)  
    protected @NotNull java.lang.Object getLock()  
    V merge​(K key, V value, @NotNull java.util.function.BiFunction<V,​V,​V> mergeFunc)  
    V putIfAbsent​(K key, V value)  
    boolean replace​(K key, V value)  
    boolean replace​(K key, V oldValue, V newValue)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.github.xanthic.cache.api.Cache

    clear, get, put, putAll, remove, size
  • Constructor Details

  • Method Details

    • computeIfAbsent

      public V computeIfAbsent​(@NotNull K key, @NotNull @NotNull java.util.function.Function<K,​V> computeFunc)
      Specified by:
      computeIfAbsent in interface io.github.xanthic.cache.api.Cache<K,​V>
    • compute

      @Nullable public V compute​(@NotNull K key, @NotNull @NotNull java.util.function.BiFunction<? super K,​? super V,​? extends V> computeFunc)
      Specified by:
      compute in interface io.github.xanthic.cache.api.Cache<K,​V>
    • computeIfPresent

      public V computeIfPresent​(@NotNull K key, @NotNull @NotNull java.util.function.BiFunction<? super K,​? super V,​? extends V> computeFunc)
      Specified by:
      computeIfPresent in interface io.github.xanthic.cache.api.Cache<K,​V>
    • putIfAbsent

      public V putIfAbsent​(@NotNull K key, @NotNull V value)
      Specified by:
      putIfAbsent in interface io.github.xanthic.cache.api.Cache<K,​V>
    • merge

      public V merge​(@NotNull K key, @NotNull V value, @NotNull @NotNull java.util.function.BiFunction<V,​V,​V> mergeFunc)
      Specified by:
      merge in interface io.github.xanthic.cache.api.Cache<K,​V>
    • replace

      public boolean replace​(@NotNull K key, @NotNull V value)
      Specified by:
      replace in interface io.github.xanthic.cache.api.Cache<K,​V>
    • replace

      public boolean replace​(@NotNull K key, @NotNull V oldValue, @NotNull V newValue)
      Specified by:
      replace in interface io.github.xanthic.cache.api.Cache<K,​V>
    • getLock

      @NotNull protected @NotNull java.lang.Object getLock()