pub struct BloomTokenLog(/* private fields */);
Expand description
Bloom filter-based TokenLog
Parameterizable over an approximate maximum number of bytes to allocate. Starts out by storing used tokens in a hash set. Once the hash set becomes too large, converts it to a bloom filter. This achieves a memory profile of linear growth with an upper bound.
Divides time into periods based on lifetime
and stores two filters at any given moment, for
each of the two periods currently non-expired tokens could expire in. As such, turns over
filters as time goes on to avoid bloom filter false positive rate increasing infinitely over
time.
Implementations§
Source§impl BloomTokenLog
impl BloomTokenLog
Sourcepub fn new_expected_items(max_bytes: usize, expected_hits: u64) -> BloomTokenLog
pub fn new_expected_items(max_bytes: usize, expected_hits: u64) -> BloomTokenLog
Construct with an approximate maximum memory usage and expected number of validation token usages per expiration period
Calculates the optimal bloom filter k number automatically.
Sourcepub fn new(max_bytes: usize, k_num: u32) -> BloomTokenLog
pub fn new(max_bytes: usize, k_num: u32) -> BloomTokenLog
Construct with an approximate maximum memory usage and a bloom filter k number
If choosing a custom k number, note that BloomTokenLog
always maintains two filters
between them and divides the allocation budget of max_bytes
evenly between them. As such,
each bloom filter will contain max_bytes * 4
bits.
Trait Implementations§
Source§impl Default for BloomTokenLog
Default to 20 MiB max memory consumption and expected one million hits
impl Default for BloomTokenLog
Default to 20 MiB max memory consumption and expected one million hits
With the default validation token lifetime of 2 weeks, this corresponds to one token usage per 1.21 seconds.