s3FifoCache<
K,V>(options):Cache<K,V>
Defined in: packages/cache/src/s3-fifo-cache.ts:226
Create a Cache that evicts with S3-FIFO (simple, static, scalable FIFO queues).
Choose it when the traffic mixes a reused hot set with long scans of keys read once, or with many keys never read again: a new key waits in a small probationary queue, a tenth of capacity, and only a key read twice there reaches the main queue, so a scan cannot push the hot set out. Keys evicted from the probationary queue are remembered, without their values, so one that returns soon enters the main queue directly; those keys stay reachable until forgotten, at most one per entry in the main queue.
get and a set of a key already held count as uses; peek and has
do not.
get, peek, has, and delete run in O(1) average time; set runs
in O(1) amortized time per entry it evicts, since an entry is passed over
at most a bounded number of times per use. Iteration is O(n) over every
slot allocated since the last clear.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”options
Section titled “options”CacheOptions<K, V>
Returns
Section titled “Returns”Cache<K, V>
Throws
Section titled “Throws”With INVALID_CAPACITY when capacity is
not a positive safe integer (or, with weigh, not a positive finite
number), MISSING_CLOCK when timeToLive comes without clock, or
INVALID_TIME_TO_LIVE when timeToLive is not a positive finite number.
Example
Section titled “Example”const cache = s3FifoCache<string, number>({ capacity: 3 })cache.set('a', 1)cache.set('b', 2)cache.set('c', 3)cache.get('a')cache.get('a')cache.set('d', 4) // [{ key: 'b', value: 2 }]: 'a' moved to the main queue