Package thredds.cache

Class DiskPersistedCache<K,V>

java.lang.Object
thredds.cache.DiskPersistedCache<K,V>
Type Parameters:
K - key type
V - value type

public final class DiskPersistedCache<K,V> extends Object
A two-tier key-value disk persisted cache

This cache is composed of a smaller in-memory LRU cache (level 1) and a disk-based storage layer for persistence (level 2). The level 1 cache 1 cache is item-limited, while the eclipse storage layer is not limited. However, values in the level 2 cache will be replaced with lazy references after 30 seconds. In this sense, the level 2 cache is only used for persistence and loading persisted values into the level 1 cache.

When entries are added to the cache, the entry is added to both the level 1 level 2 caches. If an entry already exists in either cache, it will be replaced.

When keys are requested from the cache, the level 1 cache is first checked. If the level 1 cache does not contain an entry for the key, the level 2 cache is checked. If the key is not present in the level 2 cache, a null value is returned. If the key exists, the value will be lazily loaded from the EclipseStorage layer, placed into the level 1 cache, and returned to the caller.

  • Method Details

    • at

      public static <K, V> DiskPersistedCache.Builder<K,V> at(Path cacheDir) throws IOException
      DiskPersistedCache Builder

      Type Parameters:
      K - cache key
      V - cache value
      Parameters:
      cacheDir - location of the disk persisted cache
      Returns:
      a DiskPersistedCache builder
      Throws:
      IOException - if an i/o issue related to cacheDir is encountered
    • get

      public V get(K key)
    • getOrDefault

      public V getOrDefault(K key, V defaultValue)
    • put

      public void put(K key, V val)
    • remove

      public void remove(K key)
    • numL1Keys

      public long numL1Keys()
    • numL2Keys

      public long numL2Keys()
    • reinit

      public void reinit()
      remove all cached entities from both the level 1 and level 2 caches
    • name

      public String name()
    • running

      public boolean running()
    • showL1Db

      public void showL1Db(Formatter f)
    • showL2Db

      public void showL2Db(Formatter f, int skip)
    • shutdown

      public void shutdown()