|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.aris.cache.universalcache.UniversalCache
public class UniversalCache
A least used algorithm cache for complex key which caches maximum a constant number of objects based on usage. Used as a system wide object cache, this way making more efficient use of memory. Rather than caching each class in a different cache, cache all classes using this cache in order for most used classes to be cached and least used classes to be flushed, thus providing more memory for classes that are more often used. The cache has the ability to shrink or expand according to a hit/miss ratio. This way, less memory is used when the hit ratio is high, and more memory is reserved in order to make hit ratio high if it is low. (by default this behaviour is disabled, use setAllowResize(true) to enable after instantiation. ) The cache max size is guaranteed less or equal to that initially specified. The memory used by the cache is maximum max_allowed_items*sizeOf(max(sizeOf(class1),sizeOf(class2),...)).
Constructor Summary | |
---|---|
UniversalCache(int cacheObjectsAverage)
Creates a cache with a minimum of cacheObjectsAverage/2 and a maximum of 3 x cacheObjectsAverage /2 objects. |
|
UniversalCache(int cacheObjectsMin,
int cacheObjectsMax,
float adjustFactor,
float adjustFactorUnchanged,
int dSize,
boolean allowResize)
Initialize the cache. |
Method Summary | |
---|---|
void |
clear()
Clears and initializes the cache. |
void |
dump(boolean printvalues)
Dumps the cache to System.out. |
void |
flush(java.lang.Object[] startKey)
Removes all cached items starting from startKey. |
void |
flushSynchronized(java.lang.Object[] startKey)
Synchronized version of invalidateUnder. |
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 |
java.lang.Object |
getSynchronized(java.lang.Object[] key)
Gets the value assosiated to the key. |
boolean |
isAllowResize()
|
void |
put(java.lang.Object[] key,
java.lang.Object value)
Insert/Update a key/value in the cache. |
void |
putSynchronized(java.lang.Object[] key,
java.lang.Object value)
Insert/Update a key/value in the cache. |
java.lang.Object |
remove(java.lang.Object[] key)
Removes a key/value from the cache. |
java.lang.Object |
removeSynchronized(java.lang.Object[] key)
Removes a key/value from the cache. |
void |
setAllowResize(boolean allowResize)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public UniversalCache(int cacheObjectsMin, int cacheObjectsMax, float adjustFactor, float adjustFactorUnchanged, int dSize, boolean allowResize)
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 paramCacheCallBackI
public UniversalCache(int cacheObjectsAverage)
cacheObjectsAverage
- The average number of objects that will be cached.CacheCallBackI
,
UniversalCache(int)
Method Detail |
---|
public void clear()
public int getHits()
public int getMisses()
public void putSynchronized(java.lang.Object[] key, java.lang.Object value)
key
- The keyvalue
- The value for this keypublic void put(java.lang.Object[] key, java.lang.Object value)
key
- The keyvalue
- The value for this keypublic java.lang.Object getSynchronized(java.lang.Object[] key)
key
- The key to search
public java.lang.Object get(java.lang.Object[] key)
key
- The key to search
public java.lang.Object removeSynchronized(java.lang.Object[] key)
key
- The key to remove.
public java.lang.Object remove(java.lang.Object[] key)
key
- The key to remove.
public void flushSynchronized(java.lang.Object[] startKey)
startKey
- The starting keyflush(Object[])
public void flush(java.lang.Object[] startKey)
startKey
- The key to start. All subkeys are removed.public void dump(boolean printvalues)
printvalues
- If true, it prints the values associated with the keys too.public boolean isAllowResize()
public void setAllowResize(boolean allowResize)
allowResize
- set to true to allow the cache to adjust it's size according
to hits/misses ratio.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |