Packages: org.aris.OODB org.aris.hldb org.aris.cache.UniversalCache
Documentation
: Javadoc
Org.aris.cache.UniversalCache package: Caching java objects
Version : 1.0Beta
Author : Konstantine Kougios
Known bugs : None so far.
Downloads
Included in org.aris.OODB
Purpose
Universal cache is used to cache java objects. Objects are put/get/remove’d by 1 or more keys. The caching is not for 1 type of objects but for all the objects a program needs to cache. This way, memory is used more efficiently. Instead of storing each object in it’s own cache, this cache stores all objects in a fixed size structure. The least used objects are flushed from cache for new objects to be stored in it. This way, if class A is used more than class B, eventually the cache will hold more objects of A than of B, where in typical single class caches memory would be wasted by unused B objects.
Usage
Supposedly we have 2 classes, class A and class B. Class A has a combination of 2 Integers as a key, where class B has a string.
Example 1: using UniversalCache
UniversalCache cache=new UniversalCache(averageNumberOfStoredObjects); // create the cache which will store max 3x averageNumberOfStoredObjects/2
…
…
…
A aInstance=new A(….)
cache.put(new Object[]{A.class,new Integer(5),new Integer(10)}, aInstance); // put in the cache the value of aInstance, with keys of Integer(5),Integer(10)
…
B bInstance=new B(….)
cache.put(new Object[]{B.class,”KEY”}, bInstance); // put in the cache the value of bInstance, with key of “KEY”
…
aInstance=(A)cache.get(new Object[]{A.class,new Integer(5),new Integer(10)}); // get the stored instance of A for keys (5,10)
Contact : Konstantine Kougios at ariskk@otenet.gr with subject “UniversalCache” and comments, questions, bugs found or suggestions.