Closed 0xtyls closed 2 years ago
Hi, you just need to implement CacheCallback
for your own struct, and set it by AsyncCacheBuilder
or CacheBuilder
depends on the cache type you want to use.
e.g.
struct FooCacheCallback {
// ... you code here
}
impl CacheCallback for FooCacheCallback {
// ... you code here
}
fn main() {
let cache = CacheBuilder::new(cap, max_cost)
.set_callback(FooCacheCallback::new())
.finalize()
.expect("failed to create cache");
}
I'm using AsyncCache and get this compiling error:
expected struct DefaultCacheCallback
, found struct FooCacheCallback
I figured it out. Instead of using type AsyncCache<String, PathBuf>, I need to use AsyncCache<String, PathBuf, DefaultKeyBuilder
How can I use CacheCallback? I need to delete the related file from the file system when the entry is evicted