Class FileCacheImpl

java.lang.Object
com.atlassian.plugin.cache.filecache.impl.FileCacheImpl
All Implemented Interfaces:
Cache

public class FileCacheImpl extends Object implements Cache
Implements a thread-safe FileCache.

This implementation uses a computing map LRU map to create missing entries, and an eviction listener to identify files that need to be deleted.

Concurrent control to the contents of each cache entry is implemented in StreamsCache

Since:
v2.13
  • Field Details

  • Constructor Details

    • FileCacheImpl

      public FileCacheImpl(File tmpDir, int maxSize) throws IOException
      Parameters:
      tmpDir - directory to store cache contents. Files in this dir will be deleted by constructor
      maxSize - size of the LRU cache. zero means evict-immediately
      Throws:
      IOException
  • Method Details

    • ensureNotNull

      public static OutputStream ensureNotNull(OutputStream stream)
    • cache

      public boolean cache(String bucket, String key, OutputStream out, Cache.StreamProvider provider)
      Description copied from interface: Cache
      Stream the contents identified by the key to the destination stream. Should the contents not exist in the cache a new entry should be created if the implementation is a caching implementation.
      Specified by:
      cache in interface Cache
      Parameters:
      bucket - bucket to group keys
      key - can not be null
      out - where to write the cached item to
      provider - provides the underlying item on a cache-miss
      Returns:
      if it was a cache-hit
    • cacheTwo

      public boolean cacheTwo(String bucket, String key, OutputStream out1, OutputStream out2, Cache.TwoStreamProvider provider)
      Description copied from interface: Cache
      Stream two contents identified by the key to the destination stream. Should the contents not exist in the cache a new entry should be created if the implementation is a caching implementation.
      Specified by:
      cacheTwo in interface Cache
      Parameters:
      bucket - bucket to group keys
      key - can not be null
      out1 - where to write the first cached item to
      out2 - where to write the second cached item to
      provider - provides the underlying item on a cache-miss
      Returns:
      if it was a cache-hit
    • clear

      public void clear()
      Description copied from interface: Cache
      Remove all entries in the cache.
      Specified by:
      clear in interface Cache
    • generateNextFileName

      protected String generateNextFileName()
      Atomically generates next file name for the cache file.