|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.Dictionary
java.util.Hashtable
uk.co.mullsoft.jean.components.CacheTable
public class CacheTable
This class extends Hashtable to provide a persistent cache. If objects of classes that do not implement the Cacheable Interface are placed in here then it behaves as a normal Hashtable with no persistence. If Cacheable objects are put in here then as well as being stored as in a normal Hashtable their selector part is placed in a separate Hashtable and their data part is written to disk. At system exit the save() method will save the selector Hashtable to disk. At system startup the selector hashtable is read in.
When a call is made to get() then the underlying Hahstable is accessed. If the item is not there then a check is made in the selector hashtable. If it is there then a new Cacheable object is created using the selector and the loaded data. If it is not there then null is returned as usual.
When a cacheable object is put into the hashtable then a reference is placed in both tables and the data part written out to disk (in a separate thread). When a Cacheable object is removed from the table then it is only removed from the underlying table. It is retained in the selectors hashtable but its data part is set to null so as to conserve space. When the table is saved
Cacheable,
Serialized Form| Constructor Summary | |
|---|---|
CacheTable()
Creates a new instance of CacheTable with name "default" |
|
CacheTable(java.lang.String name)
Creates a new instance of CacheTable |
|
| Method Summary | |
|---|---|
static void |
clearCacheDirectory()
clear out the cache directory. |
protected static void |
decrementCacheSize(long by)
increment the currentCacheSize |
java.util.Enumeration |
elements()
Returns an enumeration of the values in this hashtable. |
void |
finalize()
Try to catch anybody who has exited without explicitly calling save(). |
void |
forceRemove(java.lang.Object key)
|
java.lang.Object |
get(java.lang.Object key)
Returns the value to which the specified key is mapped in this hashtable |
static java.io.File |
getCacheDirectory()
get the cache directory |
static long |
getCurrentCacheSize()
Getter for property currentCacheSize. |
static long |
getMaximumCacheSize()
Getter for property maximumCacheSize. |
static int |
getNumberOfFilesToDelete()
Getter for property numberOfFilesToDelete. |
java.lang.Object |
getUninflated(java.lang.Object key)
Returns the value to which the specified key is mapped in this hashtable |
protected static void |
incrementCacheSize(long by)
increment the currentCacheSize |
void |
inflate(Cacheable ch)
|
void |
loadItems(java.lang.Object[] keys,
Cacheable[] values)
load a set of objects into the local cache but not into the memory cache |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Maps the specified key to the specified value in this hashtable. |
java.lang.Object |
remove(java.lang.Object key)
Removes the key (and its corresponding value) from this hashtable. |
void |
save()
save the selector Hashtable to disk using its name and the extension ".cache" in the cacheDirectory. |
static void |
setCacheDirectory(java.io.File newCacheDirectory)
set a new value for the cache directory |
protected static void |
setCurrentCacheSize(long newCurrentCacheSize)
Setter for property currentCacheSize. |
void |
setExample(Cacheable ex)
set an example of the class of object being cached that can be used to create new ones. |
static void |
setMaximumCacheSize(long newMaximumCacheSize)
Setter for property maximumCacheSize. |
static void |
setNumberOfFilesToDelete(int newNumberOfFilesToDelete)
Setter for property numberOfFilesToDelete. |
| Methods inherited from class java.util.Hashtable |
|---|
clear, clone, contains, containsKey, containsValue, entrySet, equals, hashCode, isEmpty, keys, keySet, putAll, rehash, size, toString, values |
| Methods inherited from class java.lang.Object |
|---|
getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public CacheTable()
public CacheTable(java.lang.String name)
name - the name of this cache table.| Method Detail |
|---|
public static java.io.File getCacheDirectory()
public static void setCacheDirectory(java.io.File newCacheDirectory)
newCacheDirectory - the new value for the cache directory. It must be an existing directorypublic static void clearCacheDirectory()
public static long getMaximumCacheSize()
public static void setMaximumCacheSize(long newMaximumCacheSize)
maximumCacheSize - New value of property maximumCacheSize.public static long getCurrentCacheSize()
protected static void setCurrentCacheSize(long newCurrentCacheSize)
currentCacheSize - New value of property currentCacheSize.protected static void incrementCacheSize(long by)
the - amount to add onprotected static void decrementCacheSize(long by)
the - amount to add onpublic static int getNumberOfFilesToDelete()
public static void setNumberOfFilesToDelete(int newNumberOfFilesToDelete)
numberOfFilesToDelete - New value of property numberOfFilesToDelete.
public void loadItems(java.lang.Object[] keys,
Cacheable[] values)
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
put in interface java.util.Mapput in class java.util.Hashtablekey - the hashtable key.value - the valuepublic void inflate(Cacheable ch)
public java.lang.Object getUninflated(java.lang.Object key)
key - a key in the hashtable
public java.lang.Object get(java.lang.Object key)
get in interface java.util.Mapget in class java.util.Hashtablekey - a key in the hashtable
public void save()
public void finalize()
finalize in class java.lang.Objectpublic java.util.Enumeration elements()
elements in class java.util.Hashtablepublic java.lang.Object remove(java.lang.Object key)
remove in interface java.util.Mapremove in class java.util.Hashtablekey - the key that needs to be removed
public void forceRemove(java.lang.Object key)
public void setExample(Cacheable ex)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||