com.atlassian.plugin.cache.filecache.impl
Class FileCacheImpl<K>

java.lang.Object
  extended by com.atlassian.plugin.cache.filecache.impl.FileCacheImpl<K>
All Implemented Interfaces:
FileCache<K>

public class FileCacheImpl<K>
extends Object
implements FileCache<K>

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 CachedFile

Since:
v2.13

Constructor Summary
FileCacheImpl(File tmpDir, int maxSize, AtomicLong filenameCounter)
           
 
Method Summary
 void clear()
          Remove all entries in the cache.
 void stream(K key, OutputStream dest, FileCacheStreamProvider input)
          Stream the contents identified by the key to the destination stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileCacheImpl

public FileCacheImpl(File tmpDir,
                     int maxSize,
                     AtomicLong filenameCounter)
              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
filenameCounter - counter for cache filenames. Passed in to allow multiple instances to share the same counter.
Throws:
IOException
Method Detail

stream

public void stream(K key,
                   OutputStream dest,
                   FileCacheStreamProvider input)
            throws DownloadException
Description copied from interface: FileCache
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:
stream in interface FileCache<K>
Parameters:
key - can not be null
dest - where to write the cached item to
input - provides the underlying item on a cache-miss
Throws:
DownloadException - if there was an error writing to dest, or reading from input, or reading from the cache

clear

public void clear()
Description copied from interface: FileCache
Remove all entries in the cache.

Specified by:
clear in interface FileCache<K>


Copyright © 2013 Atlassian. All Rights Reserved.