Package org.biojava.nbio.core.util
Class FlatFileCache
java.lang.Object
org.biojava.nbio.core.util.FlatFileCache
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
Modifier and TypeMethodDescriptionstatic 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 Details
-
addToCache
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
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
Returns the number of items in the cache. If the cache is empty, returns -1- Returns:
-
clear
Removes all elements from the cache
-