Class _LRUCache
source code
A cache of values such that least recently used element is flushed
when the cache fills.
This lets us retrieve the key given the timestamp, and the timestamp
given the key. (Also the value given either one.) That's necessary so
that we can reorder the history given a key, and also manipulate the
values dict given a timestamp.
I haven't tried changing history to a List. An earlier implementation
of history as a List was slower than what's here, but the two
implementations aren't directly comparable.
|
|
|
|
|
removeOldestEntry(self)
Remove the oldest entry from the cache. |
source code
|
|
|
|
|
|
dict
|
history
A dict from timestamp -> key
|
int
|
nextTimestamp
Timestamp to use with the next value that's added.
|
int
|
oldestTimestamp
Timestamp of the oldest element (the next one to remove), or slightly
lower than that.
|
dict
|
values
A dict from key -> (value, timestamp)
|
Initialize a new cache
- Parameters:
capacity (int) - Size of the cache (number of Sense -> Synset mappings)
|
Set the capacity of the cache.
- Parameters:
capacity (int) - new size of the cache
|
Get an item from the cache.
- Parameters:
key (unknown) - identifier of a cache entry
loadfn (function reference) - a function used to load the cached entry
- Returns:
- a cached item
|