Profectus / lib/lru-cache / LRUCache
Class: LRUCache<K, V> ​
A LRU cache intended for caching pure functions.
Type Parameters ​
• K
• V
Constructors ​
new LRUCache() ​
new LRUCache<
K,V>(maxSize):LRUCache<K,V>
Parameters ​
maxSize ​
number
The maximum size for this cache. We recommend setting this to be one less than a power of 2, as most hashtables - including V8's Object hashtable (https://crsrc.org/c/v8/src/objects/ordered-hash-table.cc)
- uses powers of two for hashtable sizes. It can't exactly be a power of two, as a .set() call could temporarily set the size of the map to be maxSize + 1.
Returns ​
LRUCache<K, V>
Defined in ​
profectus/src/lib/lru-cache.ts:23
Properties ​
maxSize ​
maxSize:
number
Defined in ​
profectus/src/lib/lru-cache.ts:13
Accessors ​
size ​
Get Signature ​
get size():
number
Returns ​
number
Defined in ​
profectus/src/lib/lru-cache.ts:27
Methods ​
get() ​
get(
key):undefined|V
Gets the specified key from the cache, or undefined if it is not in the cache.
Parameters ​
key ​
K
The key to get.
Returns ​
undefined | V
The cached value, or undefined if key is not in the cache.
Defined in ​
profectus/src/lib/lru-cache.ts:37
set() ​
set(
key,value):void
Sets an entry in the cache.
Parameters ​
key ​
K
The key of the entry.
value ​
V
The value of the entry.
Returns ​
void
Throws ​
Error, if the map already contains the key.