org.python.core.util

## Class LimitedCache<K,V>

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

-     public class LimitedCache<K,V>
      extends java.lang.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 and Description
    `LimitedCache(int capacity)` Construct a cache that will hold (at least) the specified number of entries.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(K key, V value)` Add a value corresponding to a given key.
    `V` | `get(K key)` Get a value corresponding to the key, if it was previously cached.
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### 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 Detail

    - #### 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 java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

Jython homepage