Klasse LRUCache<K,V>

java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.util.LRUCache<K,V>
Alle implementierten Schnittstellen:
Cloneable
Bekannte direkte Unterklassen:
OverflowingLRUCache

public class LRUCache<K,V> extends Object implements Cloneable
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.

Siehe auch:
  • Ungültige Referenz
    org.eclipse.jdt.internal.core.util.ILRUCacheable
  • Felddetails

    • currentSpace

      protected int currentSpace
      Amount of cache space used so far
    • spaceLimit

      protected int spaceLimit
      Maximum space allowed in cache
    • timestampCounter

      protected int timestampCounter
      Counter for handing out sequential timestamps
    • entryTable

      protected Hashtable<K,LRUCache.LRUCacheEntry<K,V>> entryTable
      Hash table for fast random access to cache entries
    • entryQueue

      protected LRUCache.LRUCacheEntry<K,V> entryQueue
      Start of queue (most recently used entry)
    • entryQueueTail

      protected LRUCache.LRUCacheEntry<K,V> entryQueueTail
      End of queue (least recently used entry)
    • DEFAULT_SPACELIMIT

      protected static final int DEFAULT_SPACELIMIT
      Default amount of space in the cache
      Siehe auch:
  • Konstruktordetails

    • LRUCache

      public LRUCache()
      Creates a new cache. Size of cache is defined by DEFAULT_SPACELIMIT.
    • LRUCache

      public LRUCache(int size)
      Creates a new cache.
      Parameter:
      size - Size of Cache
  • Methodendetails

    • clone

      public LRUCache<K,V> clone()
      Returns a new cache containing the same contents.
      Setzt außer Kraft:
      clone in Klasse Object
      Gibt zurück:
      New copy of object.
    • fillingRatio

      public double fillingRatio()
    • flush

      public void flush()
      Flushes all entries from the cache.
    • flush

      public void flush(K key)
      Flushes the given entry from the cache. Does nothing if entry does not exist in cache.
      Parameter:
      key - Key of object to flush
    • getKey

      public K getKey(K key)
    • get

      public V get(K key)
      Answers the value in the cache at the given key. If the value is not in the cache, returns null
      Parameter:
      key - Hash table key of object to retrieve
      Gibt zurück:
      Retrieved object, or null if object does not exist
    • getCurrentSpace

      public int getCurrentSpace()
      Returns the amount of space that is current used in the cache.
    • getNewestTimestampCounter

      public int getNewestTimestampCounter()
      Returns the timestamps of the most recently used element in the cache.
    • getOldestTimestampCounter

      public int getOldestTimestampCounter()
      Returns the timestamps of the least recently used element in the cache.
    • getOldestElement

      public K getOldestElement()
      Returns the lest recently used element in the cache, can return null
    • getSpaceLimit

      public int getSpaceLimit()
      Returns the maximum amount of space available in the cache.
    • keys

      public Enumeration<K> keys()
      Returns an Enumeration of the keys currently in the cache.
    • keysAndValues

      public ICacheEnumeration<K,V> keysAndValues()
      Returns an enumeration that iterates over all the keys and values currently in the cache.
    • 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.
      Parameter:
      space - Amount of space to free up
    • newInstance

      protected LRUCache<K,V> newInstance(int size)
      Returns a new LRUCache instance
    • peek

      public V peek(K key)
      Answers the value in the cache at the given key. If the value is not in the cache, returns null This function does not modify timestamps.
    • privateAdd

      protected void privateAdd(K key, V value, int space)
      Adds an entry for the given key/value/space.
    • privateAddEntry

      protected void privateAddEntry(LRUCache.LRUCacheEntry<K,V> entry, boolean shuffle)
      Adds the given entry from the receiver.
      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)
      Removes the entry from the entry queue.
      Parameter:
      shuffle - indicates whether we are just shuffling the queue (in which case, the entry table is not modified).
    • put

      public V put(K key, V value)
      Sets the value in the cache at the given key. Returns the value.
      Parameter:
      key - Key of object to add.
      value - Value of object to add.
      Gibt zurück:
      added value.
    • removeKey

      public V removeKey(K key)
      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.
    • setSpaceLimit

      public void setSpaceLimit(int limit)
      Sets the maximum amount of space that the cache can store
      Parameter:
      limit - Number of units of cache space
    • spaceFor

      protected int spaceFor(V value)
      Returns the space taken by the given value.
    • toString

      public String toString()
      Returns a String that represents the value of this object. This method is for debugging purposes only.
      Setzt außer Kraft:
      toString in Klasse Object
    • toStringContents

      protected String toStringContents()
      Returns a String that represents the contents of this object. This method is for debugging purposes only.
    • toStringFillingRation

      public String toStringFillingRation(String cacheName)
    • updateTimestamp

      protected void updateTimestamp(LRUCache.LRUCacheEntry<K,V> entry)
      Updates the timestamp for the given entry, ensuring that the queue is kept in correct order. The entry must exist