|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--org.jwarp.service.cache.Cache
This class implments the ICache interface. It implements all the basic stuff, such us controlling
access of the items, updating the cached data, e.g. removing unused data. For each cache instance
a CacheUpdateThread is started which is responsible for regularely calling the cache's update method.
The exact behaviour of the cache can be controlled by several settings:
| maxComponents: | This setting is a boundery for the objects maximally hold within the cache. If set to -1 this setting is switched off. | ||||||
| maxTime: | Determines the maximal time an item is hold in the cache. When this time is over the object will be removed from the cache. This setting garantees a minimal actuality state of each object within the cache. If this is set to -1 then this setting is ignored. | ||||||
| minAccess: | This setting determines the minimum access count an object must reach to be kept within the cache. The period checked is identical to the update period of the update thread. The value provided is a start value. If this is the only setting actually set the minAccess value is used as provided. Other settings such as the maxComponents setting lead also in a internal dynamic adaptation of the minAccess value to get the cache size as defined in the maxComponents setting. | ||||||
| updateInterval: | This is the period when the update thread is started. The update thread is responsible for throwing objects out the cache depending on the cache settings explained above. | ||||||
| sensibility: | The sensibility is the minimum difference of accesses made in maximum to a cache entry so the internal LRU table is made bigger/smaller. | tolerance: | The tolerance is the amount which the total cache size may grow bigger than the maximum objects count. Shortly everytime the total objects count in the cache supercedes the number of maximum objects allowed plus the tolerance setting an extraordinary update thread is started. | granularity: | The amount of access classes that are used for classifying the number of accesses made to objects. If you have a very big cache with lots of objects and different accesses then you may set a bigger value here. Default is 30. | tracing: | If you enable tracing all the caches activities are stored in a internal structure. You can the tell the cache to print out its activities to a print writer. The maximum number of traced items can be limited with the setMaxTraceItems method. |
| Field Summary | |
protected long |
currentMinAccess
Determines how many accesses should be made so an object can stay in the cache. |
protected boolean |
debugging
Turns on or off debugging message. |
protected java.util.Hashtable |
objects
The actually cashed objects. |
protected int |
reactionSensiblity
The sensibility is the minimum difference of accesses made in maximum to a cache entry so the internal LRU table is made bigger/smaller |
| Constructor Summary | |
Cache()
Creates a default cache. |
|
Cache(long updateInterval)
Creates a default cache setting the caches update interval. |
|
Cache(java.util.Properties properties)
Creates a default cache setting the caches value with the properties passed.. |
|
| Method Summary | |
void |
flush()
Flush the cache. |
java.lang.Object |
get(java.lang.Object key)
Returns the cached object reference or null if no object matched. |
boolean |
getDebugging()
Returns if debugging is enabled. |
java.util.Enumeration |
getKeys()
Return the currently stored keys. |
int |
getObjectCount()
Returns the currently stored objects number. |
java.util.Enumeration |
getObjects()
Returns an enumeration of the currently object in the cache. |
int |
getTolerance()
Returns the current tolerance |
long |
getUpdateIntervall()
Returns the caches update interval. |
boolean |
isTracing()
Returns if the cache is currently tracing its activities. |
void |
printCacheState(java.io.PrintWriter pw)
Prints out the caches current status to the print writer provided. |
void |
printTrace(java.io.PrintWriter pw,
boolean printDetails)
This prints out the trace information on the writer passed. |
void |
put(java.lang.Object key,
java.lang.Object object)
Puts a new object in the cache. |
java.lang.Object |
remove(java.lang.Object key)
Remove explicitely an object from the cache. |
void |
resetTracing()
Resets tracing. |
void |
setDebugging(boolean val)
Switches debugging on or off. |
protected void |
setGranularity(int accessClassCount)
Set the granularity of the access statistics. |
void |
setMaxComponents(int number)
Set the maximum numbers of objects of the cache. |
void |
setMaxComponents(int number,
int tolerance)
Sets the maximum number of objects to be hold in the cache. |
void |
setMaxTime(long maxTime)
Set the maximal time an object is hold in the cache. |
void |
setMaxTracingItems(int max)
Sets the maximum tracing barrier. |
void |
setMinAccess(int minAccess)
Set the minimalAccess default setting. |
void |
setReactionSensibility(int sens)
This changes the sensibility which is used for adapting the currentMinAccess setting when the cache is updated. |
void |
setTolerance(int tolerance)
Sets the tolerance of the cache for calling the update thread when too many objects are inserted into the cache and the update thread could not remove the superfluous ones. |
void |
setTracing(boolean tracing)
Enable or disable tracing of the caches activity. |
void |
setTracing(boolean tracing,
int maxItems)
Enable or disable tracing of the caches activity. |
void |
setUpdateIntervall(long millis)
Sets the update interval. |
void |
updateCache()
This method will be called by the update thread. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
protected java.util.Hashtable objects
protected long currentMinAccess
protected boolean debugging
protected int reactionSensiblity
| Constructor Detail |
public Cache()
public Cache(long updateInterval)
The - update interval in millispublic Cache(java.util.Properties properties)
| Method Detail |
public java.lang.Object get(java.lang.Object key)
get in interface ICacheThe - object key
public void put(java.lang.Object key,
java.lang.Object object)
put in interface ICachekey - The objects keyobject - The object to be storedpublic void setTolerance(int tolerance)
tolerance - the tolerance valuepublic int getTolerance()
public void setDebugging(boolean val)
setDebugging in interface ICacheval - true if you want to enable debuggingpublic boolean getDebugging()
getDebugging in interface ICache
public void setTracing(boolean tracing,
int maxItems)
tracing - Enable/Disable tracingmaxItems - The maximal items to be tracedpublic void setTracing(boolean tracing)
public boolean isTracing()
public void resetTracing()
public void setMaxTracingItems(int max)
The - maximal tracing items stored.
public void printTrace(java.io.PrintWriter pw,
boolean printDetails)
pw - The target printwriter.public java.lang.Object remove(java.lang.Object key)
remove in interface ICachekey - The objects keypublic void setUpdateIntervall(long millis)
setUpdateIntervall in interface ICachemillis - The updateInterval in mspublic long getUpdateIntervall()
public void setMaxComponents(int number,
int tolerance)
public void setMaxComponents(int number)
ICachesetMaxComponents in interface ICachepublic int getObjectCount()
getObjectCount in interface ICachepublic java.util.Enumeration getObjects()
getObjects in interface ICachepublic java.util.Enumeration getKeys()
getKeys in interface ICachepublic void flush()
flush in interface ICachepublic void setReactionSensibility(int sens)
setReactionSensibility in interface ICacheThe - sensibilitypublic void setMinAccess(int minAccess)
setMinAccess in interface ICacheThe - minimal acces number.public void setMaxTime(long maxTime)
setMaxTime in interface ICacheThe - maximal hosting time.public void updateCache()
updateCache in interface ICacheprotected void setGranularity(int accessClassCount)
accessClassCount - The number of classification slotspublic void printCacheState(java.io.PrintWriter pw)
The - printwriter to printout the caches contents.
|
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||