|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.aspectj.org.eclipse.jdt.internal.core.util.LRUCache
public class LRUCache
The LRUCache is a hashtable that stores a finite number of elements.
When an attempt is made to add values to a full cache, the least recently used values
in the cache are discarded to make room for the new values as necessary.
The data structure is based on the LRU virtual memory paging scheme.
Objects can take up a variable amount of cache space by implementing
the ILRUCacheable interface.
This implementation is NOT thread-safe. Synchronization wrappers would have to be added to ensure atomic insertions and deletions from the cache.
ILRUCacheable| Nested Class Summary | |
|---|---|
protected static class |
LRUCache.LRUCacheEntry
This type is used internally by the LRUCache to represent entries stored in the cache. |
class |
LRUCache.Stats
|
| Field Summary | |
|---|---|
protected int |
currentSpace
Amount of cache space used so far |
protected static int |
DEFAULT_SPACELIMIT
Default amount of space in the cache |
protected LRUCache.LRUCacheEntry |
entryQueue
Start of queue (most recently used entry) |
protected LRUCache.LRUCacheEntry |
entryQueueTail
End of queue (least recently used entry) |
protected java.util.Hashtable |
entryTable
Hash table for fast random access to cache entries |
protected int |
spaceLimit
Maximum space allowed in cache |
protected int |
timestampCounter
Counter for handing out sequential timestamps |
| Constructor Summary | |
|---|---|
LRUCache()
Creates a new cache. |
|
LRUCache(int size)
Creates a new cache. |
|
| Method Summary | |
|---|---|
java.lang.Object |
clone()
Returns a new cache containing the same contents. |
double |
fillingRatio()
|
void |
flush()
Flushes all entries from the cache. |
void |
flush(java.lang.Object key)
Flushes the given entry from the cache. |
java.lang.Object |
get(java.lang.Object key)
Answers the value in the cache at the given key. |
int |
getCurrentSpace()
Returns the amount of space that is current used in the cache. |
java.lang.Object |
getKey(java.lang.Object key)
|
int |
getNewestTimestampCounter()
Returns the timestamps of the most recently used element in the cache. |
java.lang.Object |
getOldestElement()
Returns the lest recently used element in the cache |
int |
getOldestTimestampCounter()
Returns the timestamps of the least recently used element in the cache. |
int |
getSpaceLimit()
Returns the maximum amount of space available in the cache. |
java.util.Enumeration |
keys()
Returns an Enumeration of the keys currently in the cache. |
ICacheEnumeration |
keysAndValues()
Returns an enumeration that iterates over all the keys and values currently in the cache. |
protected boolean |
makeSpace(int space)
Ensures there is the specified amount of free space in the receiver, by removing old entries if necessary. |
protected LRUCache |
newInstance(int size)
Returns a new LRUCache instance |
java.lang.Object |
peek(java.lang.Object key)
Answers the value in the cache at the given key. |
protected void |
privateAdd(java.lang.Object key,
java.lang.Object value,
int space)
Adds an entry for the given key/value/space. |
protected void |
privateAddEntry(LRUCache.LRUCacheEntry entry,
boolean shuffle)
Adds the given entry from the receiver. |
protected void |
privateRemoveEntry(LRUCache.LRUCacheEntry entry,
boolean shuffle)
Removes the entry from the entry queue. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Sets the value in the cache at the given key. |
java.lang.Object |
removeKey(java.lang.Object key)
Removes and returns the value in the cache for the given key. |
void |
setSpaceLimit(int limit)
Sets the maximum amount of space that the cache can store |
protected int |
spaceFor(java.lang.Object value)
Returns the space taken by the given value. |
java.lang.String |
toString()
Returns a String that represents the value of this object. |
protected java.lang.String |
toStringContents()
Returns a String that represents the contents of this object. |
java.lang.String |
toStringFillingRation(java.lang.String cacheName)
|
protected void |
updateTimestamp(LRUCache.LRUCacheEntry entry)
Updates the timestamp for the given entry, ensuring that the queue is kept in correct order. |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected int currentSpace
protected int spaceLimit
protected int timestampCounter
protected java.util.Hashtable entryTable
protected LRUCache.LRUCacheEntry entryQueue
protected LRUCache.LRUCacheEntry entryQueueTail
protected static final int DEFAULT_SPACELIMIT
| Constructor Detail |
|---|
public LRUCache()
DEFAULT_SPACELIMIT.
public LRUCache(int size)
size - Size of Cache| Method Detail |
|---|
public java.lang.Object clone()
clone in class java.lang.Objectpublic double fillingRatio()
public void flush()
public void flush(java.lang.Object key)
key - Key of object to flushpublic java.lang.Object getKey(java.lang.Object key)
public java.lang.Object get(java.lang.Object key)
key - Hash table key of object to retrieve
public int getCurrentSpace()
public int getNewestTimestampCounter()
public int getOldestTimestampCounter()
public java.lang.Object getOldestElement()
public int getSpaceLimit()
public java.util.Enumeration keys()
public ICacheEnumeration keysAndValues()
protected boolean makeSpace(int space)
space - Amount of space to free upprotected LRUCache newInstance(int size)
public java.lang.Object peek(java.lang.Object key)
protected void privateAdd(java.lang.Object key,
java.lang.Object value,
int space)
protected void privateAddEntry(LRUCache.LRUCacheEntry entry,
boolean shuffle)
shuffle - Indicates whether we are just shuffling the queue
(in which case, the entry table is not modified).
protected void privateRemoveEntry(LRUCache.LRUCacheEntry entry,
boolean shuffle)
shuffle - indicates whether we are just shuffling the queue
(in which case, the entry table is not modified).
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
key - Key of object to add.value - Value of object to add.
public java.lang.Object removeKey(java.lang.Object key)
key - Key of object to remove from cache.
public void setSpaceLimit(int limit)
limit - Number of units of cache spaceprotected int spaceFor(java.lang.Object value)
public java.lang.String toString()
toString in class java.lang.Objectprotected java.lang.String toStringContents()
public java.lang.String toStringFillingRation(java.lang.String cacheName)
protected void updateTimestamp(LRUCache.LRUCacheEntry entry)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||