|
Version: 1.1.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.biomoby.client.FileCache
public class FileCache
A simple cache implementation to save and later return (any) data, or to find that the given data are not available in the cache. It uses files to store data.
Constructor Summary | |
---|---|
FileCache(String rootDirName,
String rootURLName)
Constructor specifying where to create files with the cached objects. |
Method Summary | |
---|---|
String |
createId(String rootName,
String semanticType,
String syntaxType,
long lastModified,
Properties props)
It creates an 'id' in the form: rootName / semanticType / { prop1_prop2_... } (time).syntaxType The part between { and } (inclusive) will be replaced by a unique shorter string in order to create a reasonably long real file name. |
boolean |
existsInCache(String id)
It expects the 'id' in the form as created by 'createId'. |
Object |
getContents(String id)
This class does not implement this method. |
String |
getFilename(String id)
Return a fully qualified path to a file that represents the cached object identified by the 'id'. |
String |
getURL(String id)
Return a pointer to cached object identified by its 'id'. |
void |
removeFromCache(String id)
Remove cached object identified by its 'id' from the cache. |
void |
removeOlderThen(long millis)
Remove all cached objects that are in cache longer that specifies by 'millis'. |
void |
setContents(String id,
byte[] data)
Store 'data' as an object identified by 'id'. |
void |
setContents(String id,
Object data)
This class does not implement this method. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileCache(String rootDirName, String rootURLName)
<rootDirName>/cache/The all not yet existing directories (for example the last 'cache' directory) will be created for you.
'rootURLName' is used by method getURL(java.lang.String)
to return back
cached data. It serves as a prefix (perhaps including the
protocol, host and port) to returned URLs. In other words:
'rootDirName' tells where to create physical files, and
'rootULName' tells how to find these file using HTTP or other
protocols.
Method Detail |
---|
public String createId(String rootName, String semanticType, String syntaxType, long lastModified, Properties props)
createId
in interface SimpleCache
rootName
- is some high level name of the cached objectsemanticType
- is yet another feature of the cached objectsyntaxType
- is another property of the cached object
(e.i. it may be used as the file name suffix if the cache is
implemented as a filesystem)lastModified
- is time in millis indicating when the
cached object was created or modifiedprops
- are all remaining properties identifying the
cached object
public boolean existsInCache(String id)
existsInCache
in interface SimpleCache
id
- a unique ID of the cached (or possibly cached) object
public Object getContents(String id) throws IOException
getFilename(java.lang.String)
and read the returned file yourself.
getContents
in interface SimpleCache
id
- a unique ID of the object being returned
IOException
public void setContents(String id, Object data) throws IOException
setContents(String,byte[])
to store data in a file.
setContents
in interface SimpleCache
id
- a unique ID of the object being storeddata
- are being stored
IOException
public String getFilename(String id) throws IOException
SimpleFileCache
getFilename
in interface SimpleFileCache
id
- a unique ID of the cached (or possibly cached) object
IOException
- if creating the parent directories caused problempublic void setContents(String id, byte[] data) throws IOException
SimpleFileCache
setContents
in interface SimpleFileCache
id
- a unique ID of the object being storeddata
- are being stored
IOException
public String getURL(String id)
<rootURLName>/<name>where <name> is a name relative to the beginning of the cache (meaning that 'rootDirName' is not included here). If, however, the 'rootURLName ' is null it returns:
file:<name>where the <name> is the same as above.
getURL
in interface SimpleFileCache
id
- a unique IDpublic void removeFromCache(String id) throws IOException
SimpleCache
removeFromCache
in interface SimpleCache
id
- a unique ID
IOException
- if the object exists but cannot be removed
(meaning that it does not raise any exception if the
object is not anymore in the cache)public void removeOlderThen(long millis) throws IOException
SimpleFileCache
removeOlderThen
in interface SimpleFileCache
millis
- how many milliseconds must be an object stored to
be remopved by calling this method
IOException
- if any object that exists in the cache and
is targeted to be removed but cannot be removed
|
Version: 1.1.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |