|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.marringtons.file.FileCache
This class caches a defined number of disk files for reading to reduce disk access for files that are accessed repetively. It looks in the properties file for a key "file.read.cache.size" for this number. Given a file name it uses FileReader to look for and find the file. Once a file is read once it is kept in the cache and retrieved from memory when needed. When the cache fills files the least recently used files are removed. For a single-user application a small cache size of 10 would be adequate. For an Internet or Intranet application the cache size should be at least 10 per expected user. Use larger cache sizes for larger file groups.
byte[] buffer = FileCache.fetch(fileName);
if (buffer == null) Application.log("Can't file file " + fileName);
| Field Summary | |
static boolean |
disable
set to true to disable caching. |
| Constructor Summary | |
FileCache(int size)
Create a new file cache with a fixed size specified in code. |
|
FileCache(String size)
Create a new file cache with a fixed size from a properties file. |
|
FileCache(String size,
int defaultSize)
Create a new file cache with a fixed size from a properties file and a default value if the property does not exist. |
|
| Method Summary | |
void |
close()
Close cache when finished with it. |
byte[] |
fetch(String fileName)
Fetch a file either from the cache or from disk. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static boolean disable
| Constructor Detail |
public FileCache(int size)
size - maximum number of entries before LRU entries are purged.public FileCache(String size)
size - properties key for maximum number of entries before LRU entries are purged.
public FileCache(String size,
int defaultSize)
size - properties key for maximum number of entries before LRU entries are purged.defaultSize - size to use if there is none defined in property| Method Detail |
public byte[] fetch(String fileName)
throws IOException
fileName - name of file to retrieve from disk or cache
IOExceptionpublic void close()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||