import { FrequencySketch } from "https://deno.land/x/velo@1.0.0/src/policy/tiny_lfu/frequency_sketch.ts";
A probabilistic set for estimating the frequency of elements within a time
window to use as freshness metric for the TinyLFU [1] admission policy.
Employing a Count-Min Sketch[2] where the counter matrix is represented by
an array with length=width*depth
. Width is at least the given capacity of
the cache for accuracy, but is increased to the next power of two. The depth
is 4 by default.
The frequency of all entries is aged periodically using a sampling window based on the maximum number of entries in the cache. This is referred to as the reset operation by TinyLfu and keeps the sketch fresh by dividing all counters by two.
- [1] TinyLFU: A Highly Efficient Cache Admission Policy https://dl.acm.org/citation.cfm?id=3149371
- [2] An Improved Data Stream Summary: The Count-Min Sketch and its Applications http://dimacs.rutgers.edu/~graham/pubs/papers/cm-full.pdf
Type Parameters
Methods
Returns the table index associated with the given hash and depth index.
Increments counter if it is not already at maximum. Returns true if the counter was incremented, false otherwise.
Increments popularity of given item up to a maximum. Downsamples popularity if a certain threshold is reached.