Klasse OverflowingLRUCache<K,V>
- Alle implementierten Schnittstellen:
Cloneable
- Bekannte direkte Unterklassen:
BufferCache,ElementCache
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
shrink 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 putand
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.
- Siehe auch:
-
Verschachtelte Klassen - Übersicht
Von Klasse geerbte verschachtelte Klassen/Schnittstellen org.aspectj.org.eclipse.jdt.internal.core.util.LRUCache
LRUCache.LRUCacheEntry<K,V>, LRUCache.Stats -
Feldübersicht
FelderModifizierer und TypFeldBeschreibungprotected doubleIndicates how much space should be reclaimed when the cache overflows.protected intIndicates if the cache has been over filled and by how much.protected booleanIndicates whether or not timestamps should be updatedVon Klasse geerbte Felder org.aspectj.org.eclipse.jdt.internal.core.util.LRUCache
currentSpace, DEFAULT_SPACELIMIT, entryQueue, entryQueueTail, entryTable, spaceLimit, timestampCounter -
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungOverflowingLRUCache(int size) Creates a OverflowingLRUCache.OverflowingLRUCache(int size, int overflow) Creates a OverflowingLRUCache. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungclone()Returns a new cache containing the same contents.protected abstract booleanclose(LRUCache.LRUCacheEntry<K, V> entry) Returns true if the element is successfully closed and removed from the cache, otherwise false.elements()Returns an enumerator of the values in the cache with the most recently used first.doubleFor internal testing only.doubleReturns the load factor for the cache.intprotected booleanmakeSpace(int space) Ensures there is the specified amount of free space in the receiver, by removing old entries if necessary.newInstance(int size, int newOverflow) Returns a new instance of the reciever.voidFor testing purposes onlyprotected voidprivateRemoveEntry(LRUCache.LRUCacheEntry<K, V> entry, boolean shuffle) Removes the entry from the entry queue.protected voidprivateRemoveEntry(LRUCache.LRUCacheEntry<K, V> entry, boolean shuffle, boolean external) Removes the entry from the entry queue.Sets the value in the cache at the given key.Removes and returns the value in the cache for the given key.voidsetLoadFactor(double newLoadFactor) Sets the load factor for the cache.voidsetSpaceLimit(int limit) Sets the maximum amount of space that the cache can storebooleanshrink()Attempts to shrink the cache if it has overflown.toString()Returns a String that represents the value of this object.protected voidupdateTimestamp(LRUCache.LRUCacheEntry<K, V> entry) Updates the timestamp for the given entry, ensuring that the queue is kept in correct order.Von Klasse geerbte Methoden org.aspectj.org.eclipse.jdt.internal.core.util.LRUCache
flush, flush, get, getCurrentSpace, getKey, getNewestTimestampCounter, getOldestElement, getOldestTimestampCounter, getSpaceLimit, keys, keysAndValues, newInstance, peek, privateAdd, privateAddEntry, removeKey, spaceFor, toStringContents, toStringFillingRation
-
Felddetails
-
overflow
protected int overflowIndicates if the cache has been over filled and by how much. -
timestampsOn
protected boolean timestampsOnIndicates whether or not timestamps should be updated -
loadFactor
protected double loadFactorIndicates how much space should be reclaimed when the cache overflows. Inital load factor of one third.
-
-
Konstruktordetails
-
OverflowingLRUCache
public OverflowingLRUCache(int size) Creates a OverflowingLRUCache.- Parameter:
size- Size limit of cache.
-
OverflowingLRUCache
public OverflowingLRUCache(int size, int overflow) Creates a OverflowingLRUCache.- Parameter:
size- Size limit of cache.overflow- Size of the overflow.
-
-
Methodendetails
-
clone
Returns a new cache containing the same contents. -
close
Returns true if the element is successfully closed and removed from the cache, otherwise false.NOTE: this triggers an external remove from the cache by closing the object.
-
elements
Returns an enumerator of the values in the cache with the most recently used first. -
fillingRatio
public double fillingRatio()- Setzt außer Kraft:
fillingRatioin KlasseLRUCache<K,V>
-
getEntryTable
For internal testing only. This method exposed only for testing purposes!- Gibt zurück:
- Hashtable of entries
-
getLoadFactor
public double getLoadFactor()Returns the load factor for the cache. The load factor determines how much space is reclaimed when the cache exceeds its space limit.- Gibt zurück:
- double
-
getOverflow
public int getOverflow()- Gibt zurück:
- The space by which the cache has overflown.
-
makeSpace
protected boolean makeSpace(int space) Ensures there is the specified amount of free space in the receiver, by removing old entries if necessary. Returns true if the requested space was made available, false otherwise. May not be able to free enough space since some elements cannot be removed until they are saved. -
newInstance
Returns a new instance of the reciever. -
printStats
public void printStats()For testing purposes only -
privateRemoveEntry
Removes the entry from the entry queue. CallsprivateRemoveEntrywith the external functionality enabled.- Setzt außer Kraft:
privateRemoveEntryin KlasseLRUCache<K,V> - Parameter:
shuffle- indicates whether we are just shuffling the queue (in which case, the entry table is not modified).
-
privateRemoveEntry
protected void privateRemoveEntry(LRUCache.LRUCacheEntry<K, V> entry, boolean shuffle, boolean external) Removes the entry from the entry queue. If external is true, the entry is removed without checking if it can be removed. It is assumed that the client has already closed the element it is trying to remove (or will close it promptly). If external is false, and the entry could not be closed, it is not removed and the pointers are not changed.- Parameter:
shuffle- indicates whether we are just shuffling the queue (in which case, the entry table is not modified).
-
put
Beschreibung aus Klasse kopiert:LRUCacheSets the value in the cache at the given key. Returns the value. -
remove
Removes and returns the value in the cache for the given key. If the key is not in the cache, returns null.- Parameter:
key- Key of object to remove from cache.- Gibt zurück:
- Value removed from cache.
-
setLoadFactor
Sets the load factor for the cache. The load factor determines how much space is reclaimed when the cache exceeds its space limit.- Parameter:
newLoadFactor- double- Löst aus:
IllegalArgumentException- when the new load factor is not in (0.0, 1.0]
-
setSpaceLimit
public void setSpaceLimit(int limit) Beschreibung aus Klasse kopiert:LRUCacheSets the maximum amount of space that the cache can store- Setzt außer Kraft:
setSpaceLimitin KlasseLRUCache<K,V> - Parameter:
limit- Number of units of cache space
-
shrink
public boolean shrink()Attempts to shrink the cache if it has overflown. Returns true if the cache shrinks to less than or equal tofSpaceLimit. -
toString
Returns a String that represents the value of this object. This method is for debugging purposes only. -
updateTimestamp
Updates the timestamp for the given entry, ensuring that the queue is kept in correct order. The entry must exist.This method will do nothing if timestamps have been disabled.
- Setzt außer Kraft:
updateTimestampin KlasseLRUCache<K,V>
-