embedded_cache/
embedded-cache.rs1use kevy_embedded::{Config, EvictionPolicy, Store};
8
9fn main() -> std::io::Result<()> {
10 let s = Store::open(
11 Config::default()
12 .with_max_memory(200 * 1024)
13 .with_eviction(EvictionPolicy::AllKeysLru),
14 )?;
15
16 for i in 0..10_000 {
17 let key = format!("user:{i:05}");
18 let val = format!("user-payload-{i}");
19 s.set(key.as_bytes(), val.as_bytes())?;
20 }
21
22 println!("dbsize after insert flood: {}", s.dbsize());
23 println!("used_memory: {} bytes (limit 200 KiB)", s.used_memory());
24 println!("evictions_total: {}", s.evictions_total());
25
26 let recent = format!("user:0{}", 9999);
28 println!(
29 "user:09999 → {:?}",
30 s.get(recent.as_bytes())?.as_deref().map(String::from_utf8_lossy)
31 );
32
33 Ok(())
34}