Class CacheSimple<K,V>

java.lang.Object
org.apache.jena.atlas.lib.cache.CacheSimple<K,V>
All Implemented Interfaces:
Cache<K,V>

public class CacheSimple<K,V> extends Object implements Cache<K,V>
A simple fixed size cache that uses the hash code to address a slot. The clash policy is to overwrite.

The cache has very low overhead - there is no object creation during lookup or insert.

This cache is not thread safe.

  • Constructor Details

    • CacheSimple

      public CacheSimple(int size)
    • CacheSimple

      public CacheSimple(int size, BiConsumer<K,V> dropHandler)
  • Method Details

    • clear

      public void clear()
      Specified by:
      clear in interface Cache<K,V>
    • containsKey

      public boolean containsKey(K key)
      Description copied from interface: Cache
      Does the cache contain the key?
      Specified by:
      containsKey in interface Cache<K,V>
    • getIfPresent

      public V getIfPresent(K key)
      Description copied from interface: Cache
      Get from cache - or return null.
      Specified by:
      getIfPresent in interface Cache<K,V>
    • getOrFill

      public V getOrFill(K key, Callable<V> callable)
      Description copied from interface: Cache
      Get from cache; if not present, call the Callable to try to fill the cache. This operation should be atomic.
      Specified by:
      getOrFill in interface Cache<K,V>
    • get

      public V get(K key, Function<K,V> function)
      Description copied from interface: Cache
      Get from cache; if not present, call the Function to fill the cache slot. This operation should be atomic.
      Specified by:
      get in interface Cache<K,V>
    • getOrFillNoSync

      public static <K, V> V getOrFillNoSync(Cache<K,V> cache, K key, Function<K,V> function)
      Implementation of getOrFill based on Cache.get and Cache.put This function is not thread safe.
    • getOrFillNoSync

      public static <K, V> V getOrFillNoSync(Cache<K,V> cache, K key, Callable<V> callable)
      Implementation of getOrFill based on Cache.get and Cache.put This function is not thread safe.
    • put

      public void put(K key, V thing)
      Description copied from interface: Cache
      Insert into the cache
      Specified by:
      put in interface Cache<K,V>
    • remove

      public void remove(K key)
      Description copied from interface: Cache
      Remove from cache - return true if key referenced an entry
      Specified by:
      remove in interface Cache<K,V>
    • size

      public long size()
      Description copied from interface: Cache
      Current size of cache
      Specified by:
      size in interface Cache<K,V>
    • keys

      public Iterator<K> keys()
      Description copied from interface: Cache
      Iterate over all keys. Iterating over the keys requires the caller be thread-safe.
      Specified by:
      keys in interface Cache<K,V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Cache<K,V>