Skip to content
FutureBlitz

    Install

    Import std.collections.lru_cache

    std.collections.lru_cache

    LruCache<K, V>: up to Capacity entries, dropping the one used least recently to make room for a new key. Get and Add count as uses, but Peek, Contains, and going over the entries don't. Its entries are a Map's, in the order they were last used, so a use moves an entry to the end.

    std/collections/lru_cache.fb

    Types

    LruCache class

    @DebugEntries Public Class LruCache<K: Hashable, V> Implements Iterable<(K, V)>, Cloneable

    A Map that holds up to its Capacity, letting go of the entry used least recently to make room for a new one.

    std/collections/lru_cache.fb, line 11

    • @PanicsAtCaller Public New(capacity: Int) constructor #

      An empty LruCache that holds up to capacity entries, which must be 1 or more.

    • Public Property Count: Int property #

      How many entries it holds.

    • Public Property Capacity: Int property #

      How many entries it holds at most.

    • Public Method Get(key: K): V? method #

      The key's value, or Null when it isn't there. A key that's there is used.

    • Public Method Peek(key: K): V? method #

      The key's value, or Null when it isn't there, without using the key.

    • Public Method Contains(key: K): Bool method #

      Whether key has an entry, which doesn't count as using it.

    • Public Method Add(key: K, value: V): (K, V)? method #

      Adds an entry, or gives an existing key its new value, and uses the key. When that leaves more than Capacity entries, the least recently used one goes, and Add gives it, or else Null.

    • Public Method Remove(key: K): Bool method #

      Removes the key's entry, and tells whether there was one.

    • Public Method Clear() method #

      Takes every entry out.

    • @PanicsAtCaller Public Method Resize(capacity: Int) method #

      Holds up to capacity entries from now on, which must be 1 or more, dropping the least recently used ones beyond it.

    • Public Method Keys(): K[] method #

      The keys, least recently used first.

    • Public Method Values(): V[] method #

      The values, in their keys' order.

    • Public Method Clone(): LruCache<K, V> method #

      A new LruCache with the same entries, in the same order, and Capacity.

    • Public Method Iterate(): MapIterator<K, V> method #

      Each key and its value, least recently used first. Giving a key a new value or using one while going over them panics, as adding or removing one does.

    Extends

    LruCache extend

    Extend LruCache<K, V> Implements Printable

    No doc comment.

    std/collections/lru_cache.fb, line 107

    Report an issue with this page or with FutureBlitz on GitHub.