Class ThreadLocalCacheAccessor<K,V>

java.lang.Object
com.atlassian.confluence.cache.ThreadLocalCacheAccessor<K,V>

public class ThreadLocalCacheAccessor<K,V> extends Object
A type-safe way of accessing the threadlocal cache
See Also:
  • Method Details

    • newInstance

      public static <K, V> ThreadLocalCacheAccessor<K,V> newInstance()
      Factory method (for type inference)
      Returns:
      an appropriately parameterised cache accessor
    • put

      public void put(K key, V value)
      Put a value in the threadlocal cache
      Parameters:
      key - the key to cache
      value - the value to cache
    • get

      public V get(K key)
      Retrieve a value from the threadlocal cache
      Parameters:
      key - the key for the cache value
      Returns:
      the appropriate value, or null if nothing was cached for that key, or the cache has not been initialised
    • getOrCompute

      public @NonNull V getOrCompute(@NonNull K key, @NonNull Supplier<V> supplier)
      Retrieve a value from the threadlocal cache or from the given supplier.
      Parameters:
      key - the key for the cache value
      supplier - supplier that can produce the value if needed
      Returns:
      the appropriate value as stored in the cache of produced by the supplier
      Since:
      7.0.1
    • init

      public void init()
    • isInit

      public boolean isInit()
    • flush

      public void flush()
      Flush all thread local cache values.
      Since:
      5.9