How does the max_cost works?
LinkTed opened this issue · comments
LinkTed commented
Hi,
I have a question about the max_cost
argument in the AsyncCache
. When I set it to 2 and insert 2 item each have 1 cost, then one of the item is missing. Maybe I misinterpret something here. Code:
use stretto::AsyncCache;
#[tokio::main]
async fn main() {
let c = AsyncCache::new(20, 2, tokio::spawn).unwrap();
c.insert(1, 2, 1).await;
c.insert(2, 3, 1).await;
c.wait().await.unwrap();
c.get(&1).unwrap(); // Get a panic
}
Al Liu commented
There is an internal_cost
that will auto-add for each item if you do not set ignore_internal_cost
to true when building the cache. See https://github.com/al8n/stretto#ignore_internal_cost.