jaemk / cached

Rust cache structures and easy function memoization

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get all cached values?

gitmalong opened this issue · comments

It is possible to get all key, value pairs from the cache?

#[cached(
    result = true,
    convert = r##"{ format!("{}", address) }"##,
    type = "SizedCache<String, Option<A>>",
    create = "{ SizedCache::with_size(10000) }",
    sync_writes = true
)]

Yes, the macro creates a cache instance with the name of the function in all caps (see

let cache = SLOW_FN.lock().unwrap();
). After you lock the instance, you can use these iterator methods on SizedCached
pub fn key_order(&self) -> impl Iterator<Item = &K> {