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 void
addToCache
(String key, File fileToCache) The file is read and the bytes stored immediately.static void
clear()
Removes all elements from the cachestatic InputStream
getInputStream
(String key) Gets the cached file as an InputStream.static int
size()
Returns the number of items in the cache.
-
Method Details
-
addToCache
The file is read and the bytes stored immediately.Once added,
fileToCache
can 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
InputStream
or 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
-