info.ephyra.util
Class FileCache

java.lang.Object
  extended by info.ephyra.util.FileCache

public class FileCache
extends java.lang.Object

The FileCache is a simple implementation of a permanent cache. The entries of the cache are accessed by keys. Both keys and entries are strings, and there may be an arbitrary number of entries for a key.

The entries are stored in files in a directory which is specified when the cache handler is created. There is one file for each key and the MD5 checksum of the key is used as the filename.

Version:
2006-11-27
Author:
Nico Schlaefer

Field Summary
private  java.lang.String cacheDir
          The directory where the files are stored.
 
Constructor Summary
FileCache(java.lang.String cacheDir)
          Creates a new cache handler and sets the directory of the cache.
 
Method Summary
private  java.lang.String getMD5(java.lang.String s)
          Computes the MD5 checksum of a string.
 java.lang.String[] read(java.lang.String key)
          Read the entries for the given key from the cache.
 boolean write(java.lang.String key, java.lang.String[] entries)
          Writes new entries to the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cacheDir

private java.lang.String cacheDir
The directory where the files are stored.

Constructor Detail

FileCache

public FileCache(java.lang.String cacheDir)
Creates a new cache handler and sets the directory of the cache.

Parameters:
cacheDir - cache directory
Method Detail

getMD5

private java.lang.String getMD5(java.lang.String s)
Computes the MD5 checksum of a string.

Parameters:
s - the string
Returns:
checksum, or null if the MD5 algorithm is not available

read

public java.lang.String[] read(java.lang.String key)
Read the entries for the given key from the cache.

Parameters:
key - the key
Returns:
the entries, or null if the key is not in the cache

write

public boolean write(java.lang.String key,
                     java.lang.String[] entries)
Writes new entries to the cache. Existing entries with the given key are overwritten.

Parameters:
key - the key
entries - the entries
Returns:
true iff the entries could be written to the cache