|
|||||||||
| Home >> All >> com >> lutris >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.lutris.util
Class LRUCache

java.lang.Objectcom.lutris.util.LRUCache
- public class LRUCache
- extends java.lang.Object
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.
- Version:
- $Revision: 1.7.12.1 $
| Nested Class Summary | |
private class |
LRUCache.Node
|
| Field Summary | |
private java.util.Hashtable |
cache
|
private int |
currentSize
|
private LRUCache.Node |
head
|
private int |
maxSize
|
private LRUCache.Node |
tail
|
| 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? |
private boolean |
deleteLRU()
|
private void |
deleteNode(LRUCache.Node node)
|
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. |
private void |
insertNode(LRUCache.Node node)
|
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 |
| Field Detail |
maxSize
private int maxSize
currentSize
private int currentSize
cache
private java.util.Hashtable cache
head
private LRUCache.Node head
tail
private LRUCache.Node tail
| Constructor Detail |
LRUCache
public LRUCache(int maxSize)
- Create a new, empty cache.
| Method Detail |
getSize
public int getSize()
- Returns the total size of the items in the cache.
If all the items were added with the default size of 1,
this is the number of items in the cache.
getMaxSize
public int getMaxSize()
- Returns the maxmimum number of items allowed in the cache.
add
public void add(java.lang.Object key, java.lang.Object item)
- Add an object to the cache, with a default size of 1.
If the cache is full, the oldest items will be deleted to make room.
The item becomes the "newest" item.
add
public void add(java.lang.Object key, java.lang.Object item, int size)
- Add an object to the cache.
If the cache is full, the oldest items will be deleted to make room.
The item becomes the "newest" item.
get
public java.lang.Object get(java.lang.Object key)
- Fetch an item from the cache. Returns null if not found.
The item becomes the "newest" item.
remove
public java.lang.Object remove(java.lang.Object key)
- Remove an item from the cache.
containsKey
public boolean containsKey(java.lang.Object key)
- Does the cache contain the given key?
clear
public void clear()
- Delete all the items from the cache.
insertNode
private void insertNode(LRUCache.Node node)
deleteNode
private void deleteNode(LRUCache.Node node)
deleteLRU
private boolean deleteLRU()
toString
public java.lang.String toString()
- Returns a string describing the contents of the cache.
|
|||||||||
| Home >> All >> com >> lutris >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
com.lutris.util.LRUCache