|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.aris.cache.idcache.IdCache
public class IdCache
A least used cache which caches a max number of objects based on usage. Values must not be null. Callback functions are called in case of an put, get, remove
CacheCallBackI
Constructor Summary | |
---|---|
IdCache(int cacheObjectsAverage,
CacheCallBackI cacheCallBack)
Creates a cache with a minimum of cacheObjectsAverage/2 and a maximum of 3 x cacheObjectsAverage /2 objects. |
|
IdCache(int cacheObjectsMin,
int cacheObjectsMax,
float adjustFactor,
float adjustFactorUnchanged,
int dSize,
CacheCallBackI cacheCallBack)
Initialize the cache. |
Method Summary | |
---|---|
void |
addJustToCache(java.lang.Object key,
java.lang.Object value)
This just adds the key/value to the cache, without calling callbacks or checking if the key exists. |
void |
adjustMaxSize(int dSize)
Adjust the size of the cache. |
void |
dump(boolean printvalues)
Dumps the cache to System.out. |
java.lang.Object |
get(java.lang.Object key)
Gets the value assosiated to the key. |
int |
getHits()
Gets the cache hits |
int |
getMisses()
Gets the cache misses |
void |
IdCache0(int cacheObjectsMin,
int cacheObjectsMax,
float adjustFactor,
float adjustFactorUnchanged,
int dSize,
CacheCallBackI cacheCallBack)
|
java.lang.Object |
insert(java.lang.Object key,
java.lang.Object value)
Insert a key/value in the cache/store. |
java.lang.Object |
remove(java.lang.Object key)
Removes a key/value from the cache. |
java.lang.Object |
removeOnlyFromCache(java.lang.Object key)
Removes this key only from the cache. |
boolean |
update(java.lang.Object key,
java.lang.Object value)
Update a key/value in the cache/store. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public IdCache(int cacheObjectsMin, int cacheObjectsMax, float adjustFactor, float adjustFactorUnchanged, int dSize, CacheCallBackI cacheCallBack)
cacheObjectsMin
- The minimum number of objects that will be cachedcacheObjectsMax
- The maximum number of objects that will be cachedadjustFactor
- The formula
hits/misses < adjustFactor - adjustFactorUnchanged
decides wheather the cache will be increased , and the formula
hits/misses > adjustFactor + adjustFactorUnchanged
decides wheather the cache will be decreased (free memory).
The increase/decrease are performed in dSize steps.adjustFactorUnchanged
- See the adjustFactor paramdSize
- See the adjustFactor paramcacheCallBack
- A callback class that will be called every time the cache
needs to fetch/remove a key.CacheCallBackI
public IdCache(int cacheObjectsAverage, CacheCallBackI cacheCallBack)
cacheObjectsAverage
- The average number of objects that will be cached.cacheCallBack
- The callback.CacheCallBackI
,
IdCache(int, CacheCallBackI)
Method Detail |
---|
public void adjustMaxSize(int dSize)
dSize
- The dSize. It is added to the cache max size. If negative, and cacheSize>newCacheSize, all the extra
elements will be removed.public int getHits()
public int getMisses()
public void IdCache0(int cacheObjectsMin, int cacheObjectsMax, float adjustFactor, float adjustFactorUnchanged, int dSize, CacheCallBackI cacheCallBack)
IdCache
public boolean update(java.lang.Object key, java.lang.Object value) throws java.lang.Exception
key
- The key to updatevalue
- The new value for this key
java.lang.Exception
public java.lang.Object insert(java.lang.Object key, java.lang.Object value) throws java.lang.Exception
key
- The key to add, it must not already existvalue
- The value for this key
java.lang.Exception
public void addJustToCache(java.lang.Object key, java.lang.Object value)
key
- The keyvalue
- The valuepublic java.lang.Object get(java.lang.Object key) throws java.lang.Exception
key
- The key to search
java.lang.Exception
public java.lang.Object removeOnlyFromCache(java.lang.Object key)
key
- The key to remove
public java.lang.Object remove(java.lang.Object key) throws java.lang.Exception
key
- The key to remove.
java.lang.Exception
public void dump(boolean printvalues)
printvalues
- If true, it prints the values associated with the keys too.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |