jaemk / cached

Rust cache structures and easy function memoization
MIT License
1.57k stars 95 forks source link

Cache clear operation #197

Open 9999years opened 7 months ago

9999years commented 7 months ago

Currently, there is no way to clear caches. For a DiskCache, this snippet does not seem to work (edit: the remove_expired_entries logic is broken, see #198 for a fix):

// This does not seem to work:
let lifespan = cache.cache_set_lifespan(0);
cache.remove_expired_entries();
match lifespan {
    Some(lifespan) => {
        cache.cache_set_lifespan(lifespan);
    }
    None => {
        // Uhh...
    }
}

Additionally, there's no method to remove the lifespan, so if there wasn't an expiration policy set before we called cache_set_lifespan there's no way to restore that state when we're done.