|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.melati.poem.util.Cache
public final class Cache
A store whose capacity has a guaranteed lower limit but whose upper limit is bounded by the amount of memory available to the JVM. The lower limit can be adjusted after cache creation. Elements added to the cache once the cache size exceeds the lower limit (the cache is full) force the least recently used (LRU) item off the held list. Items which are removed from the held list are not deleted but converted to soft references: available to be retrieved if they are not garbage collected first. The cache cannot contain nulls, as there would be no mechanism to distinguish between a held null value and an unheld value. There is no mechanism for invalidating the cache, reducing its size to zero mearly allows all its members to be garbage collected. Ideally, having been created, objects remain in the cache; however this is impracticable when the possible size of the sum of cached objects exceeds available memory. The performance of the cache depends upon the pattern of accesses to it. An LRU cache such as this assumes a normal distribution of accesses. The state of the cache can be monitored by using the reporting objects, see for example org.melati.admin.Status.
Nested Class Summary | |
---|---|
class |
Cache.InconsistencyException
Thrown if one or more problems are discovered with cache consistency. |
class |
Cache.Info
A class which enables reporting upon the state of the Cache . |
Constructor Summary | |
---|---|
Cache(int maxSize)
Constructor with maximum size. |
Method Summary | |
---|---|
void |
delete(Object key)
Remove from cache. |
void |
dump()
Output to syserr. |
void |
dumpAnalysis()
Dump to Syserr. |
Object |
get(Object key)
Return an object from the Cache, null if not found. |
Cache.Info |
getInfo()
|
Enumeration<Object> |
getReport()
Report on the status of the cache. |
int |
getSize()
Get maximum size of Cache. |
void |
iterate(Procedure f)
Apply function to all items in cache, only ignoring items where the value has been garbage collected. |
void |
put(Object key,
Object value)
Add an Object to the cache. |
void |
setSize(int maxSize)
Set maximum size of Cache. |
void |
trim(int maxSize_P)
Reduce number of units held in the cache, without changing its size. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Cache(int maxSize)
maxSize
- maximum size cache may grow toMethod Detail |
---|
public void setSize(int maxSize)
maxSize
- maximum size cache may grow topublic int getSize()
public void trim(int maxSize_P)
maxSize_P
- maximum number of units to holdpublic void delete(Object key)
key
- cache key fieldpublic void put(Object key, Object value)
key
- the Object to use as a lookupvalue
- the Object to put in the cachepublic Object get(Object key)
key
- the cache key
public void iterate(Procedure f)
f
- Procedure to apply to all members of cachepublic Enumeration<Object> getReport()
public Cache.Info getInfo()
public void dumpAnalysis()
public void dump()
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |