Crate disklru

Source
Expand description

DiskLRU is an experimental LRU store implemented in Rust.

It works as a simple key-value store and is powered by sled which is a lightweight pure-rust high-performance transactional embedded database.

It expires entries automatically passed a given number, following the LRU (least recently used) strategy, which is a quite common cache replacement policy.

DiskLRU icon

§Examples

use disklru::Store;

let mut store = Store::open_temporary(4).unwrap();
store.insert(&1, &10).unwrap();
store.insert(&2, &20).unwrap();
store.insert(&3, &30).unwrap();
store.insert(&4, &40).unwrap();
store.insert(&5, &50).unwrap();
// key1 has been dropped, size is limited to 4
assert_eq!(Some(2), store.lru().unwrap());
assert_eq!(Some(20), store.get(&2).unwrap());
// getting key2 has made key3 the least recently used item
assert_eq!(Some(3), store.lru().unwrap());
assert_eq!(Some(40), store.get(&4).unwrap());
// getting key4 makes it the most recently used item
assert_eq!("[3: 30, 5: 50, 2: 20, 4: 40]", format!("{}", store));
store.flush().unwrap(); // commit

Modules§

sled

Structs§

Dump
Complete dump of a LRU store, easily (de)serializable.
Export
Export a LRU store.
ExportKeys
Export the keys of a LRU store.
ExportValues
Export the values of a LRU store.
Iter
Iterator over a LRU store.
Keys
Iterator over the keys of a LRU store.
Store
LRU store, backed by by sled.
Values
Iterator over the values of a LRU store.

Enums§

Error

Constants§

BUG_REPORT_URL
URL to report bugs.

Type Aliases§

Result