|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.exolab.core.foundation.LruObjectCache
public class LruObjectCache
This class is a global object cache for database objects. It is sycn' ed with the data store and is used to improve the performance of the overall system by minimizing the number of times an object is stremed in and out of the data store.
The algorithm is quite simplistic implementation of an LRU cache whose capacity is specified during object construction time.The cache has basically two operations 'insert' and 'remove'. When inserting objects into the cache, and the cache is full, then the 'least used object' will be evicted.
The LRU algorithm is implemented as a doubly linked list with references to the first and last elements in the list. The element at the end of the list is the least used element and the element at the top of a list is the most used element.
Constructor Summary | |
---|---|
LruObjectCache(int size)
Instantiate an instance of this cache with the specified number of entries. |
Method Summary | |
---|---|
void |
clear()
Clear all the entries in the cache |
java.util.Enumeration |
elements()
Return an enumeration of all the elements in the cache, Most recently used ones first. |
java.lang.Object |
get(java.lang.Object key)
Return the object with the specified key from the cache. |
int |
getFreeSlots()
Return the number of free slots inthe cache |
int |
getUsedSlots()
Return the number of entries in the cache |
double |
hitMissRatio()
Return the hit:miss ratio. |
void |
insert(java.lang.Object key,
java.lang.Object object)
Insert the object with the following key into the cache. |
void |
remove(java.lang.Object key)
Remove the object with the specified key from the cache. |
protected org.exolab.core.foundation.CacheEntry |
removeFromCache(org.exolab.core.foundation.CacheEntry entry)
Remove the specified entry from the cache and return it to the client. |
protected org.exolab.core.foundation.CacheEntry |
removeFromCache(java.lang.Object key)
Remove the element with the specified key from the cache and return it to the client.If the element does not exist then return null |
protected void |
touchCacheEntry(java.lang.Object key,
java.lang.Object object)
Return an enumeration of entries in the cache. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LruObjectCache(int size)
size
- size of the cacheMethod Detail |
---|
public void insert(java.lang.Object key, java.lang.Object object)
key
- object keyobject
- object to cachepublic void remove(java.lang.Object key)
key
- object keypublic java.lang.Object get(java.lang.Object key)
key
- object key
public void clear()
public double hitMissRatio()
Can be used to monitor the effectiveness of the cache
public int getUsedSlots()
public int getFreeSlots()
public java.util.Enumeration elements()
protected void touchCacheEntry(java.lang.Object key, java.lang.Object object)
key
- object keyobject
- object valueprotected org.exolab.core.foundation.CacheEntry removeFromCache(org.exolab.core.foundation.CacheEntry entry)
entry
- entry to remove
protected org.exolab.core.foundation.CacheEntry removeFromCache(java.lang.Object key)
key
- key of object to remove
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |