Package org.biojava.nbio.core.util
Class FlatFileCache
- java.lang.Object
-
- org.biojava.nbio.core.util.FlatFileCache
-
public class FlatFileCache extends Object
Provides a cache for storing multiple small files in memory. Can be used to e.g cache gzip compressed PDB files for avoiding disk IO bottlenecks. Note this is just a wrapper for the singleton cache.- Author:
- Andreas Prlic.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddToCache(String key, File fileToCache)The file is read and the bytes stored immediately.static voidclear()Removes all elements from the cachestatic InputStreamgetInputStream(String key)Gets the cached file as an InputStream.static intsize()Returns the number of items in the cache.
-
-
-
Method Detail
-
addToCache
public static void addToCache(String key, File fileToCache)
The file is read and the bytes stored immediately. Once added,fileToCachecan be modified or deleted and the cached values will not change.- Parameters:
key-fileToCache- A readable file, of Integer.MAX bytes length or less.
-
getInputStream
public static InputStream getInputStream(String key)
Gets the cached file as an InputStream. Clients should check for null as the item might have expired in the cache.- Parameters:
key-- Returns:
- An
InputStreamor null.
-
size
public static int size()
Returns the number of items in the cache. If the cache is {@}, returns -1- Returns:
-
clear
public static void clear()
Removes all elements from the cache
-
-