Comments (5)
Futures- thanks ^^
from moka.
Finished developing and #20 has been merged into the master branch. I am going to release Moka v0.5.0 with this feature in a day or so.
from moka.
Published Moka v0.5.0 to crates.io.
from moka.
Thanks for your suggestion. I think this would be a good feature to add. I will work on it once I finish working on another feature (#12).
Which Moka Cache
implementation are you going to use? moka::sync::Cache or moka::future::Cache?
from moka.
Hi @Dessix
I created a topic branch and added the following methods to the future cache:
async fn get_or_insert_with(&self, key: K, init: impl Future<Output = V>) -> V
- This method takes a key and a future to initialize the value.
- If the key does not exist in the cache and no other
get_or_insert_with
orget_or_try_insert_with
method is already running for the key, it awaits for the future, inserts the value returned from the future to the cache, and returns the value to the caller. - If other method is already running (the future is being awaited), it waits for the other method to complete and returns the value.
async fn get_or_try_insert_with<F>(&self, key: K, init: F) -> Result<V, Arc<Box<dyn Error>>>
where
F: Future<Output = Result<V, Box<dyn Error>>>
- This method is similar to
get_or_insert_with
but the future resolves intoResult<V, Box<dyn std::error::Error>>
instead ofV
. - A value is inserted to the cache only when the future resolves into
Ok(V)
.
Please check the unit tests out as they will show you how to use them (test1 and test2). Let me know what you think.
from moka.
Related Issues (20)
- Entry `and_compute` method for performing an insert, update, or remove operation with single closure HOT 9
- Add support for `Immediate` notification delivery mode to `future` cache HOT 1
- [help] Conditionally disabling the cache, and logging when data retrieved from cache HOT 8
- Cache with max capacity of zero should not cache anything
- Proposal: support insert key with expire time? HOT 16
- CI: Disable external CI services on temporary merge-queue branches?
- Statistics for metrics HOT 3
- `get_with` deadlock HOT 13
- `.blocking().invalidate(key)` doesn't trigger eviction listener HOT 1
- RUSTSEC-2020-0168: mach is unmaintained HOT 2
- Can the eviction strategy be configured? HOT 8
- Upgrade the cache policy from TinyLFU to W-TinyLFU
- Bump the MSRV to 1.60
- optionally_try_get_with in moka::future::Cache HOT 1
- feature request: remove method HOT 2
- Use `std::thread::available_parallelism()` instead of `num_cpus` dependency
- Eviction listener not always called. HOT 2
- Cache housekeeper can panic (seen after 50M+ insertions) HOT 4
- CI: Miri test causes a complie error with Rust nightly-2023-05-27 HOT 2
- Implement Serialize trait for debugging webserver? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moka.