|
Bali Share 1.1.18 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--oracle.bali.share.collection.LRUCache
Acts like a hashtable with a limited amount of space. After the capacity has been reached, the least-gotten item is chucked. This is a "least-recently-used" scheme. The LRUCache is initialized with a certain cache size. The cache size determines the maximum number of items that can be cached. When an object is accessed by key through one of the get() methods, it is regarded as having been "used", and is put at the head of the list of "used" objects in the cache. When an object further down the list is accessed through a get() method, or by being added through one of the put() methods, the initial object is bumped one slot down the "used" list. The "used" list is not allowed to grow longer than the number of unique objects in the cache. Once the object is pushed to the last spot in the "used" list, then it may be pushed off the list by any put() of a different object. When an object is "pushed off the list", it means that a get() call on the cache with the object's key will return null. For example:
import oracle.bali.share.collection.LRUCache;
public class Test
{
public static void main(String[] argc)
{
LRUCache c = new LRUCache(5);
int i;
for(i=0;i<5;i++) {
c.put(i,""+i);
}
c.get(1);
c.put(5,"5");
c.put(6,"6");
System.out.println("c.get(1)="+c.get(1));
System.out.println("c.get(0)="+c.get(0));
}
}
Running the above example should give you:
c.get(1)=1
c.get(0)=null
Hashtable
Constructor Summary | |
LRUCache(int size)
Constructor. |
Method Summary | |
void |
clear()
Clears the cache. |
java.lang.Object |
get(int key)
Convenience method for getting values where the key is an integer. |
java.lang.Object |
get(java.lang.Object key)
Gets the value for the given key. |
void |
put(int key,
java.lang.Object value)
Convenience method for putting values where the key is an integer. |
void |
put(java.lang.Object key,
java.lang.Object value)
Puts a key, value pair in the cache. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public LRUCache(int size)
size
- the number of items kept before least-recently-used ones are
discarded.Method Detail |
public java.lang.Object get(int key)
key
- the integer keypublic void put(int key, java.lang.Object value)
key
- the integer keyvalue
- the valuepublic java.lang.Object get(java.lang.Object key)
key
- the keypublic void put(java.lang.Object key, java.lang.Object value)
key
- the keyvalue
- the valuepublic void clear()
|
Bali Share 1.1.18 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |