intrusive-lru-cache

Crates.iointrusive-lru-cache
lib.rsintrusive-lru-cache
version
sourcesrc
created_at2024-11-23 08:51:05.919834
updated_at2024-12-07 04:14:27.795527
descriptionAn LRU cache implementation using intrusive data structures
homepage
repositoryhttps://github.com/novacrazy/intrusive_lru_cache
max_upload_size
id1458326
Cargo.toml error:TOML parse error at line 23, column 1 | 23 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Nova (novacrazy)

documentation

https://docs.rs/intrusive-lru-cache

README

Intrusive LRU Cache

crates.io Documentation MIT/Apache-2 licensed

This crate provides an LRU Cache implementation that is based on combining an intrusive doubly linked list and an intrusive red-black tree, in the same node. Both data structures share the same allocations, which makes it quite efficient for a linked structure.

The [LRUCache] structure itself is not intrusive, and works like a regular cache. The intrusive part of the crate name is due to the intrusive structures used internally.

Example

use intrusive_lru_cache::LRUCache;

let mut lru: LRUCache<&'static str, &'static str> = LRUCache::default();

lru.insert("a", "1");
lru.insert("b", "2");
lru.insert("c", "3");

let _ = lru.get("b"); // updates LRU order

assert_eq!(lru.pop(), Some(("a", "1")));
assert_eq!(lru.pop(), Some(("c", "3")));
assert_eq!(lru.pop(), Some(("b", "2")));
assert_eq!(lru.pop(), None);

Cargo Features

  • atomic (default): Enables atomic links within the intrusive structures, making it thread-safe if K and V are Send/Sync. If you disable this feature, you can still use the cache in a single-threaded context.
Commit count: 26

cargo fmt