Class LimitedCache<K,V>

java.lang.Object
org.python.core.util.LimitedCache<K,V>

public class LimitedCache<K,V> extends Object
Not for application use, a cache of recently given results from some costly function. This is only public so we can reach it from the run-time. The user sets a nominal size for the cache. The cache will grow to this size and a little more, but from time to time discard the "little more" on the basis of a score that depends on recency of use.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LimitedCache(int capacity)
    Construct a cache that will hold (at least) the specified number of entries.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(K key, V value)
    Add a value corresponding to a given key.
    get(K key)
    Get a value corresponding to the key, if it was previously cached.
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • LimitedCache

      public LimitedCache(int capacity)
      Construct a cache that will hold (at least) the specified number of entries. (It will sometimes contain a few more so we don't have to scan the cache with every addition.)
      Parameters:
      capacity - the number of entries required
  • Method Details

    • get

      public V get(K key)
      Get a value corresponding to the key, if it was previously cached.
      Parameters:
      key - against which cached
      Returns:
      the cached value or null if not present
    • add

      public void add(K key, V value)
      Add a value corresponding to a given key.
      Parameters:
      key - against which to cache the value
      value - to store
    • toString

      public String toString()
      Overrides:
      toString in class Object