Import std.collections.lru_cache
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.
Examples
Local cache = LruCache<String, Int>(2)
cache.Add("a", 1)
cache.Add("b", 2)
Expect(cache.Get("a") == 1)
// "b" is now the least recently used, so it goes to make room.
Expect(cache.Add("c", 3) == ("b", 2))
Expect(cache.Keys() == ["a", "c"])std/collections/lru_cache.fb, line 25
-
An empty LruCache that holds up to
capacityentries, which must be 1 or more. -
How many entries it holds.
-
How many entries it holds at most.
-
The
key's value, or Null when it isn't there. A key that's there is used. -
The
key's value, or Null when it isn't there, without using thekey. -
Whether
keyhas an entry, which doesn't count as using it. -
Adds an entry, or gives an existing
keyits new value, and uses thekey. When that leaves more than Capacity entries, the least recently used one goes, and Add gives it, or else Null. -
Removes the
key's entry, and tells whether there was one. -
Takes every entry out.
-
Holds up to
capacityentries from now on, which must be 1 or more, dropping the least recently used ones beyond it. -
The keys, least recently used first.
-
The values, in their keys' order.
-
A new LruCache with the same entries, in the same order, and Capacity.
-
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.
Report an issue with this page or with FutureBlitz on GitHub.