|
Nuxeo ECM Projects 5.4.3-SNAPSHOT | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.nuxeo.common.file.LRUFileCache
public class LRUFileCache
A LRU cache of File
s with capped filesystem size.
When a new file is put in the cache, if the total size becomes more that the maximum size then least recently access entries are removed until the new file fits.
A file will never be actually removed from the filesystem while the File
object returned by getFile(java.lang.String)
is still referenced.
The cache keys are restricted to a subset of ASCII: letters, digits and dashes. Usually a MD5 or SHA1 hash is used.
Field Summary | |
---|---|
static Pattern |
SIMPLE_ASCII
Allowed key pattern, used as file path. |
Constructor Summary | |
---|---|
LRUFileCache(File dir,
long maxSize)
Constructs a cache in the given directory with the given maximum size (in bytes). |
Method Summary | |
---|---|
void |
clear()
Clears the cache. |
File |
getFile(String key)
Gets a file from the cache. |
int |
getNumberOfItems()
Gets the number of items in the cache. |
long |
getSize()
Gets the size of the cache, in bytes. |
File |
getTempFile()
Creates a temporary file. |
File |
putFile(String key,
File file)
Puts a file in the cache. |
File |
putFile(String key,
InputStream in)
Puts a file in the cache. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Pattern SIMPLE_ASCII
Constructor Detail |
---|
public LRUFileCache(File dir, long maxSize)
dir
- the directory to use to store cached filesmaxSize
- the maximum size of the cache (in bytes)Method Detail |
---|
public long getSize()
FileCache
getSize
in interface FileCache
public int getNumberOfItems()
FileCache
getNumberOfItems
in interface FileCache
public File getTempFile() throws IOException
FileCache
getTempFile
in interface FileCache
IOException
public File putFile(String key, InputStream in) throws IOException
The key is used as a file name in the directory cache.
putFile
in interface FileCache
key
- the cache keyin
- the input stream to cache (closed afterwards)
IOException
public File putFile(String key, File file) throws IllegalArgumentException, IOException
The file must have been created through FileCache.getTempFile()
. The file
is "given" to this method, who will delete it or rename it.
The key is used as a file name in the directory cache.
putFile
in interface FileCache
key
- the cache keyfile
- the file to cache
IllegalArgumentException
- if the key is illegal
IOException
public File getFile(String key)
FileCache
A returned file will never be deleted from the filesystem while the returned file object is still referenced, although it may be purged from the cache.
getFile
in interface FileCache
key
- the cache key
null
if absentpublic void clear()
FileCache
Files will not be deleted from the filesystm while the returned file objects are still referenced.
clear
in interface FileCache
|
Nuxeo ECM Projects 5.4.3-SNAPSHOT | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |