Rust · LRU cache in Rust · no dependency but clap

Every eviction,
in plain sight.

Flashvault is an LRU cache in Rust with a capacity bound, TTL expiry, and live hit-rate stats, all of it readable end to end. Set some keys below and watch the eviction order move.

0
Hits
0
Misses
0
Evictions
0%
Hit rate

most-recently-used first · red row is what the next insert would evict · state resets with the button, not on reload

How it works

A HashMap for lookup and an intrusive doubly linked list for order, so both get and put stay O(1).

1

Slab of nodes

Entries live in a flat Vec of slots. A free list lets removed slots be reused instead of leaking space.

2

Intrusive list

Each node carries prev and next indices, so moving a key to the front on a hit is a pointer swap, not a scan.

3

Capacity bound

A put that would exceed capacity evicts the tail, the least-recently-used entry, before inserting.

4

TTL on read

Expiry is checked lazily at get time. An expired entry counts as a miss and an expiration, then is removed.

5

Injectable clock

A Clock trait separates real time from a settable TestClock, so TTL tests are deterministic, no sleeping.

6

Live stats

Hits, misses, evictions, expirations, and size are counted as they happen and read back with one call.

Try it from the command line.

The same cache the demo above ports to JavaScript, running for real.

# run the canned workload and print the stats it produces
cargo run -- --capacity 3 demo

# interactive repl: set, get, del, keys, stats
cargo run -- repl