xfetch-rs
About
Rust crate for Optimal Probabilistic Cache Stampede Prevention aka XFetch algorithm
It can be used in conjunction with cache containers like LRU cache to implement cache expiration and re-computation in parallel environment like multi-thread / multi-process computing.
It is very efficient because the algorithm does not need coordination (no locks) between processes.
Examples
Create a single cache entry and test it's expiration:
# ;
#
use CacheEntry;
use Duration;
let entry = builder
.with_ttl
.build;
assert!;
The CacheEntry can be used with any cache library.
For example the lru crate:
use LruCache;
use CacheEntry;
use Duration;
;
Plot showing the simulated probability of early expiration of different system:
References
- Wikipedia Cache Stampede.
- Vattani, A.; Chierichetti, F.; Lowenstein, K. (2015), Optimal Probabilistic Cache Stampede Prevention (PDF), 8 (8), VLDB, pp. 886–897, ISSN 2150-8097.
- Jim Nelson, Internet Archive, RedisConf17 - Preventing cache stampede with Redis & XFetch.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.