|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.cache.CmsLruCache
public class CmsLruCache
Implements an LRU (last recently used) cache.
The idea of this cache is to separate the caching policy from the data structure where the cached objects are stored. The advantage of doing so is, that the CmsFlexLruCache can identify the last-recently-used object in O(1), whereas you would need at least O(n) to traverse the data structure that stores the cached objects. Second, you can easily use the CmsFlexLruCache to get an LRU cache, no matter what data structure is used to store your objects.
The cache policy is affected by the "costs" of the objects being cached. Valuable cache costs might be the byte size of the cached objects for example.
To add/remove cached objects from the data structure that stores them, the objects have to implement the methods defined in the interface I_CmsLruCacheObject to be notified when they are added/removed from the CmsFlexLruCache.
I_CmsLruCacheObject
Constructor Summary | |
---|---|
CmsLruCache(long theMaxCacheCosts,
long theAvgCacheCosts,
int theMaxObjectCosts)
The constructor with all options. |
Method Summary | |
---|---|
boolean |
add(I_CmsLruCacheObject theCacheObject)
Adds a new object to this cache. |
void |
clear()
Removes all cached objects in this cache. |
long |
getAvgCacheCosts()
Returns the average costs of all cached objects. |
long |
getMaxCacheCosts()
Returns the max costs of all cached objects. |
int |
getMaxObjectCosts()
Returns the max allowed costs per cached object. |
int |
getObjectCosts()
Returns the current costs of all cached objects. |
I_CmsLruCacheObject |
remove(I_CmsLruCacheObject theCacheObject)
Removes an object from the list of all cached objects in this cache, no matter what position it has inside the list. |
int |
size()
Returns the count of all cached objects. |
java.lang.String |
toString()
Returns a string representing the current state of the cache. |
boolean |
touch(I_CmsLruCacheObject theCacheObject)
Touch an existing object in this cache, in the sense that it's "last-recently-used" state is updated. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CmsLruCache(long theMaxCacheCosts, long theAvgCacheCosts, int theMaxObjectCosts)
theMaxCacheCosts
- the maximum cache costs of all cached objectstheAvgCacheCosts
- the average cache costs of all cached objectstheMaxObjectCosts
- the maximum allowed cache costs per object. Set theMaxObjectCosts to -1 if you don't want to limit the max. allowed cache costs per objectMethod Detail |
---|
public boolean add(I_CmsLruCacheObject theCacheObject)
If add the same object more than once, the object is touched instead.
theCacheObject
- the object being added to the cache
public void clear()
public long getAvgCacheCosts()
public long getMaxCacheCosts()
public int getMaxObjectCosts()
public int getObjectCosts()
public I_CmsLruCacheObject remove(I_CmsLruCacheObject theCacheObject)
theCacheObject
- the object being removed from the list of all cached objects
public int size()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean touch(I_CmsLruCacheObject theCacheObject)
theCacheObject
- the object being touched
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |