Rust · LRU cache in Rust · no dependency but clap
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.
most-recently-used first · red row is what the next insert would evict · state resets with the button, not on reload
A HashMap for lookup and an intrusive doubly linked list for order, so both get and put stay O(1).
Entries live in a flat Vec of slots. A free list lets removed slots be reused instead of leaking space.
Each node carries prev and next indices, so moving a key to the front on a hit is a pointer swap, not a scan.
A put that would exceed capacity evicts the tail, the least-recently-used entry, before inserting.
Expiry is checked lazily at get time. An expired entry counts as a miss and an expiration, then is removed.
A Clock trait separates real time from a settable TestClock, so TTL tests are deterministic, no sleeping.
Hits, misses, evictions, expirations, and size are counted as they happen and read back with one call.
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