Class DiskCacheStore

java.lang.Object
org.microproxy.cache.DiskCacheStore
All Implemented Interfaces:
CacheStore

public final class DiskCacheStore extends Object implements CacheStore
Keeps responses as files in a directory, so the cache survives restarts (and can serve while offline). Each variant is one file named after a hash of its URL and Vary values, written to a temporary file and moved into place. The index of what is stored lives in memory, rebuilt from the files' headers at startup; the least recently used files go first when the size limit is reached. One store should own its directory.
  • Constructor Details

    • DiskCacheStore

      public DiskCacheStore(Path dir, long maxSize) throws IOException
      Opens (creating if needed) a store in dir, indexing the entries already there.
      Parameters:
      dir - the directory backing the response cache
      maxSize - the most CachedResponse.weight() to hold, in bytes
      Throws:
      IOException - if the cache directory cannot be created or read
  • Method Details

    • get

      public List<CachedResponse> get(String key)
      Description copied from interface: CacheStore
      The stored variants for key (a URL), most recently stored first; empty if none.
      Specified by:
      get in interface CacheStore
      Parameters:
      key - the URL whose variants to retrieve
      Returns:
      the stored variants for key (a URL), most recently stored first; empty if none
    • put

      public void put(CachedResponse response)
      Description copied from interface: CacheStore
      Stores response, replacing the variant of its key with the same vary values.
      Specified by:
      put in interface CacheStore
      Parameters:
      response - the response being handled
    • remove

      public void remove(String key)
      Description copied from interface: CacheStore
      Removes every variant stored for key.
      Specified by:
      remove in interface CacheStore
      Parameters:
      key - the URL whose variants to remove
    • size

      public long size()
      Description copied from interface: CacheStore
      Returns the total CachedResponse.weight() of what is stored.
      Specified by:
      size in interface CacheStore
      Returns:
      the total CachedResponse.weight() of what is stored
    • count

      public int count()
      Description copied from interface: CacheStore
      Returns the number of stored responses (variants).
      Specified by:
      count in interface CacheStore
      Returns:
      the number of stored responses (variants)