Skip to main content

Crate lru_ovo

Crate lru_ovo 

Source
Expand description

一个线程安全、异步友好的双层 LRU 缓存库。 A thread-safe, async-friendly two-tier LRU cache library.

缓存由易失 LRU 层和带容量上限的持久 LRU 层组成。热 key 在命中次数达到阈值后 会从易失层提升到持久层;持久层容量满时同样按 LRU 淘汰。 The cache consists of a volatile LRU tier and a bounded persistent LRU tier. Hot keys are promoted after their hit count reaches the threshold; the persistent tier also evicts by LRU when it reaches its capacity.

use lru_ovo::{CacheConfig, LruCache};


let cache = LruCache::with_config(CacheConfig::new(2, 2, 2));
block_on(cache.insert("hot", 10));
block_on(cache.insert("cold", 20));

block_on(cache.get(&"hot"));
block_on(cache.get(&"hot"));

assert!(block_on(cache.is_persistent(&"hot")));
assert_eq!(block_on(cache.total_len()), 2);

Re-exports§

pub use core::CacheConfig;
pub use core::CacheConfigError;
pub use core::CacheIter;
pub use core::LruCache;

Modules§

core
双层 LRU 缓存的核心实现。 Core implementation of a two-tier LRU cache.