-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question/Request] Async functions #27
Comments
Thank you for the detailed description. In my view, this crate is useful for very simple tasks, but doesn't intend to provide a general caching layer. If you want to cache results of network calls, it sounds too complicated for what this crate is promising, and it might be a lot easier and productive to build a custom cache layer yourself. |
mre
added a commit
to mre/terraphim-ai
that referenced
this issue
Jan 9, 2024
This enables caching support for `index` requests using `cached`. In comparison to `memoize`, `cached` has a few advantages for our use-case: - `memoize` doesn't support async functions. See dermesser/memoize#27 - Return types in `memoize` need to be `Clone`, which is not the case for `Error` and it's not trivial to change that, because upstream errors like `serde_json::Error` and `std::io::Error` are not `Clone`. There are ways around it, (e.g. by using `String` as error types or implementing a `newtype`, but let's see if we can avoid that. `cached` supports these properties out of the box. The only caveat is, that `self` arguments are not supported, which is why I moved the `HashMap` generation into a separate function (`index_inner`).
mre
added a commit
to mre/terraphim-ai
that referenced
this issue
Jan 9, 2024
This is a proof-of-concept of caching `index` requests with `memoize`. It works, but there are a few downsides: * `memoize` doesn't support async functions. See dermesser/memoize#27 * Return types need to be `Clone`, which is not the case for `Error` and it's not trivial to change that, because upstream errors like `serde_json::Error` and `std::io::Error` are not `Clone`. There are ways around it, (e.g. by using `String` as error types or implementing a `newtype`, but let's see if we can avoid that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for this crate, works really great.
I would have one use case, that currently isn't supported: When trying to apply the macro to an async function, it doesn't compile (because the returned Future is not clonable).
A typical use case would be caching of network requests.
Currently, I have a workaround for this, but it feels rather complicated or indirect:
task::spawn_blocking
as described hereBecause I have no idea about macros I wonder if it would be possible to add a
async_memoize
version that calls the async (memoized) function and how much work that would be.The text was updated successfully, but these errors were encountered: