|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.jdt.internal.core.util.LRUCache
org.eclipse.jdt.internal.core.OverflowingLRUCache
public abstract class OverflowingLRUCache
The OverflowingLRUCache
is an LRUCache which attempts
to maintain a size equal or less than its fSpaceLimit
by removing the least recently used elements.
The cache will remove elements which successfully close and all elements which are explicitly removed.
If the cache cannot remove enough old elements to add new elements
it will grow beyond fSpaceLimit
. Later, it will attempt to
shink back to the maximum space limit.
The method close
should attempt to close the element. If
the element is successfully closed it will return true and the element will
be removed from the cache. Otherwise the element will remain in the cache.
The cache implicitly attempts shrinks on calls to put
and
setSpaceLimit
. Explicitly calling the shrink
method
will also cause the cache to attempt to shrink.
The cache calculates the used space of all elements which implement
ILRUCacheable
. All other elements are assumed to be of size one.
Use the #peek(Object)
and #disableTimestamps()
method to
circumvent the timestamp feature of the cache. This feature is intended to be used
only when the #close(LRUCacheEntry)
method causes changes to the cache.
For example, if a parent closes its children when #close(LRUCacheEntry) is called,
it should be careful not to change the LRU linked list. It can be sure it is not causing
problems by calling #peek(Object)
instead of #get(Object)
method.
LRUCache
Constructor Summary | |
---|---|
OverflowingLRUCache(int size)
Creates a OverflowingLRUCache. |
|
OverflowingLRUCache(int size,
int overflow)
Creates a OverflowingLRUCache. |
Method Summary | |
---|---|
java.lang.Object |
clone()
Returns a new cache containing the same contents. |
java.util.Enumeration |
elements()
Returns an enumerator of the values in the cache with the most recently used first. |
double |
fillingRatio()
|
java.util.Hashtable |
getEntryTable()
For internal testing only. |
double |
getLoadFactor()
Returns the load factor for the cache. |
int |
getOverflow()
|
void |
printStats()
For testing purposes only |
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 |
remove(java.lang.Object key)
Removes and returns the value in the cache for the given key. |
void |
setLoadFactor(double newLoadFactor)
Sets the load factor for the cache. |
void |
setSpaceLimit(int limit)
Sets the maximum amount of space that the cache can store |
boolean |
shrink()
Attempts to shrink the cache if it has overflown. |
java.lang.String |
toString()
Returns a String that represents the value of this object. |
Methods inherited from class org.eclipse.jdt.internal.core.util.LRUCache |
---|
flush, flush, get, getCurrentSpace, getKey, getSpaceLimit, keys, keysAndValues, peek, removeKey, toStringFillingRation |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public OverflowingLRUCache(int size)
size
- Size limit of cache.public OverflowingLRUCache(int size, int overflow)
size
- Size limit of cache.overflow
- Size of the overflow.Method Detail |
---|
public java.lang.Object clone()
clone
in class LRUCache
public java.util.Enumeration elements()
public double fillingRatio()
fillingRatio
in class LRUCache
public java.util.Hashtable getEntryTable()
public double getLoadFactor()
public int getOverflow()
public void printStats()
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in class LRUCache
key
- Key of object to add.value
- Value of object to add.
public java.lang.Object remove(java.lang.Object key)
key
- Key of object to remove from cache.
public void setLoadFactor(double newLoadFactor) throws java.lang.IllegalArgumentException
newLoadFactor
- double
java.lang.IllegalArgumentException
- when the new load factor is not in (0.0, 1.0]public void setSpaceLimit(int limit)
setSpaceLimit
in class LRUCache
limit
- Number of units of cache spacepublic boolean shrink()
fSpaceLimit
.
public java.lang.String toString()
toString
in class LRUCache
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |