Is moka::future::Cache blocking insert has similar efficiency comparing to the moka::sync::Cache insert? #239
-
Hi @tatsuya6502 Have some question regarding to blocking insert for moka::future::Cache. I saw in the doc, https://docs.rs/moka/latest/moka/future/struct.BlockingOp.html#method.insert , this is recommanded to be used when need to insert from synchronous code. I am curious if this operation has same efficiency as sync cache insert operation( https://docs.rs/moka/latest/moka/sync/struct.Cache.html#method.insert) I did some very basic source code dive, looks the blocking insert for future cache underline depends on Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @LMJW
You are right (as of Moka v0.10.0). However, I was thinking to deprecate Let me think a bit more, to see if there is a way to keep But if not, you will have to use something like // Create a cache.
let cache = moka::future::Cache::new(100);
// In your synchronous code, insert an entry using `block_on`
// and async version of `insert`.
futures_executor::block_on(cache.insert(1, 1));
// get the value.
println!("{:?}", cache.get(&1)); |
Beta Was this translation helpful? Give feedback.
Hi @LMJW
You are right (as of Moka v0.10.0).
However, I was thinking to deprecate
blocking()
method offuture::Cache
in v0.11.0 and eventually remove. This is becausefuture::Cache
in v0.11.0 will no longer be able to share the samebase_cache::BaseCache
implementation withsync::Cache
. In order to support some features like #228 (comment),future::Cache
should start to use async version of locks throughou…