-
Notifications
You must be signed in to change notification settings - Fork 93
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
Supporting references #64
Comments
This is tricky since the caches generated by the macros will always need to be at the global / #[cached(use_argument_cache="my_cache")]
fn calculate(my_cache: &mut SizedCache<&str, usize>, input: &str) -> usize {
input.len()
}
let mut cache = SizedCache::with_size(200);
let res = calculate(&mut cache, "big"); But this feels like something that should be done with just a helper function that copies the macro's inner logic fn calculate(input: &str) -> usize {
input.len()
}
let mut cache = SizedCache::with_size(200);
let res = cached::with_cache(&mut cache, calculate, "input_str");
// except I guess it's gotta be a macro to support variadic args
let res = cached::with_cache!(&mut cache, calculate, "input_str"); Each of these would also require relaxing the constraints of the |
Gotcha, yeah I figured there were good reasons for the current constraints / approach. Can you clarify what challenges arise because the cache is static? I don't mean to disagree, I just don't have much experience in working with static variables in rust. |
The macros basically expand to
So since the cache will outlive the function inputs and outputs, they need to be things that the cache can "own" and hand out |
You can use |
@jaemk Maybe |
Hi! I recently picked up cached and it enabled me to very quickly set up some caches for hot functions. I think this project is awesome.
As I began to optimize the rest of my codebase, it quickly became clear that cloning cached values was a bottleneck (mostly just the memory allocation, I was storing
Vec<String>
). After some thought, I realized that my use case could live off of references to the cached values.I believed that cached doesn't support this sort of behavior; is it something you would consider adding? I am happy to help with implementation / flesh out the proposal a bit if it seems in scope for this project.
Thanks for building this in the first place!
The text was updated successfully, but these errors were encountered: