|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.exist.storage.cache.GClockCache
Cache implementation based on the GClock algorithm. Implements a mixture between LFU (Last Frequently Used) and LRU (Last Recently Used) replacement policies. The class uses reference counts to track references to cached objects. Each call to the add method increments the reference count of the object. If the cache is full, the object to be removed is determined by decrementing the reference count for each object until an object with reference count = 0 is found. The implementation tends to replace younger objects first.
| Field Summary | |
protected Accounting |
accounting
|
protected CacheManager |
cacheManager
|
protected int |
count
|
protected double |
growthFactor
|
protected int |
hitsOld
|
protected Cacheable[] |
items
|
protected Long2ObjectHashMap |
map
|
protected int |
size
|
protected int |
used
|
| Fields inherited from interface org.exist.storage.cache.Cache |
LOG |
| Constructor Summary | |
GClockCache(int size,
double growthFactor,
double growthThreshold)
|
|
| Method Summary | |
void |
add(Cacheable item)
Add the item to the cache. |
void |
add(Cacheable item,
int initialRefCount)
Add the item to the cache. |
boolean |
flush()
Call release on all items, but without actually removing them from the cache. |
Cacheable |
get(Cacheable item)
Retrieve an item from the cache. |
Cacheable |
get(long key)
Retrieve an item by its key. |
int |
getBuffers()
Get the size of this cache. |
int |
getFails()
Get the number of times where an object could not be found in the cache. |
java.lang.String |
getFileName()
|
double |
getGrowthFactor()
Returns the factor by which the cache should grow if it can be resized. |
int |
getHits()
Get the number of times where an object has been successfully loaded from the cache. |
int |
getLoad()
|
int |
getThrashing()
|
int |
getUsedBuffers()
Get the number of buffers currently used. |
boolean |
hasDirtyItems()
Returns true if the cache contains any dirty items that need to be written to disk. |
void |
remove(Cacheable item)
Remove an item from the cache. |
protected Cacheable |
removeOne(Cacheable item)
|
void |
resize(int newSize)
Resize the cache. |
void |
setCacheManager(CacheManager manager)
Set the CacheManager object that controls this cache. |
void |
setFileName(java.lang.String name)
|
protected void |
shrink(int newSize)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected Cacheable[] items
protected int count
protected int size
protected Long2ObjectHashMap map
protected int used
protected int hitsOld
protected Accounting accounting
protected double growthFactor
protected CacheManager cacheManager
| Constructor Detail |
public GClockCache(int size,
double growthFactor,
double growthThreshold)
| Method Detail |
public void add(Cacheable item)
Cache
add in interface Cacheitem -
public void add(Cacheable item,
int initialRefCount)
Cache
add in interface Cacheitem - initialRefCount - the initial reference count for the itempublic Cacheable get(Cacheable item)
Cache
get in interface Cacheitem -
public Cacheable get(long key)
Cache
get in interface Cachekey - a unique key, usually the page number
public void remove(Cacheable item)
Cache
remove in interface Cacheitem - public boolean flush()
Cache
flush in interface Cachepublic boolean hasDirtyItems()
Cache
hasDirtyItems in interface Cacheprotected Cacheable removeOne(Cacheable item)
public int getBuffers()
Cache
getBuffers in interface Cachepublic int getUsedBuffers()
Cache
getUsedBuffers in interface Cachepublic double getGrowthFactor()
CacheCacheManager.
getGrowthFactor in interface Cachepublic int getHits()
Cache
getHits in interface Cachepublic int getFails()
Cache
getFails in interface Cachepublic int getThrashing()
public void setCacheManager(CacheManager manager)
Cache
setCacheManager in interface Cachemanager - public void resize(int newSize)
CacheCacheManager. The newSize parameter
can either be larger or smaller than the current
cache size.
resize in interface CachenewSize - the new size of the cache.protected void shrink(int newSize)
public int getLoad()
getLoad in interface Cachepublic void setFileName(java.lang.String name)
setFileName in interface Cachepublic java.lang.String getFileName()
getFileName in interface Cache
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||