|
EAF 7.4 Implementation | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lutris.util.LRUCache
public class LRUCache
This class implements a fixed size Least-Recently-Used cache. The cache has a maximum size specified when it is created. When an item is added to the cache, if the cache is already at the maximum size the least recently used item is deleted, then the new item is added.
The only two methods that count as "using" the object (for the
least-recently-used algorithm) are add()
and
get()
.
The items cached are refered to by keys, just like a Hashtable.
Constructor Summary | |
---|---|
LRUCache(int maxSize)
Create a new, empty cache. |
Method Summary | |
---|---|
void |
add(java.lang.Object key,
java.lang.Object item)
Add an object to the cache, with a default size of 1. |
void |
add(java.lang.Object key,
java.lang.Object item,
int size)
Add an object to the cache. |
void |
clear()
Delete all the items from the cache. |
boolean |
containsKey(java.lang.Object key)
Does the cache contain the given key? |
java.lang.Object |
get(java.lang.Object key)
Fetch an item from the cache. |
int |
getMaxSize()
Returns the maxmimum number of items allowed in the cache. |
int |
getSize()
Returns the total size of the items in the cache. |
java.lang.Object |
remove(java.lang.Object key)
Remove an item from the cache. |
java.lang.String |
toString()
Returns a string describing the contents of the cache. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public LRUCache(int maxSize)
maxSize
- The maxmimum size of the items allowed to be in the cache.
Since the size of an item defaults to 1, this is normally the
number of items allowed in the cache.
When this limit is reached, the "oldest" items are deleted to
make room for the new item, so the total size of the cache
(the sum of the sizes of all the items it contains)
does not exceed the specified limit.Method Detail |
---|
public int getSize()
public int getMaxSize()
public void add(java.lang.Object key, java.lang.Object item)
key
- The key used to refer to the object when calling get()
.item
- The item to add to the cache.public void add(java.lang.Object key, java.lang.Object item, int size)
key
- The key used to refer to the object when calling get()
.item
- The item to add to the cache.size
- How large is the object? This counts against the maximim size
specified when the cache was created.public java.lang.Object get(java.lang.Object key)
key
- The key used to refer to the object when add()
was called.
public java.lang.Object remove(java.lang.Object key)
key
- The key used to refer to the object when add()
was called.
public boolean containsKey(java.lang.Object key)
key
- The key used to refer to the object when add()
was called.
public void clear()
public java.lang.String toString()
toString
in class java.lang.Object
|
EAF 7.4 Implementation | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |