-
Notifications
You must be signed in to change notification settings - Fork 94
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
Ability to clear/defeat cache stores #10
Comments
That's certainly something that could be added in some capacity! Maybe adding a cached! {
WOMP: SizedCache<(u32), u32> = SizedCache::with_size(50);
fn womp(n: u32) -> u32 = {
use cached::Cached;
let mut cache = WOMP.lock().unwrap();
// this could be resetting instead
cache.cache_set((1), 1);
cache.cache_set((2), 2);
cache.cache_set((3), 3);
n
}
}
pub fn main() {
womp(10);
{
use cached::Cached;
let cache = WOMP.lock().unwrap();
println!("size=4 -> {:?}", cache.cache_size() == 4);
}
} |
@jaemk I see, is there a way to add that trait method without adding it to the macro invocation? Not sure I understand, I'm unfamiliar with creating custom Rust macros. |
Yes, the trait method could be added here in lib.rs and then implemented for all the stores in stores.rs. The macros wouldn't need to be updated |
added in #14 |
Is there a way to use this functionality in combination with the |
@emirror-de the use cached::Cached;
use cached::proc_macro::cached;
#[cached]
fn my_func() -> i32 { ... }
#[cached(name = "MY_FUNC_2")]
fn my_funky_func() -> i32 { ... }
{
MY_FUNC.lock().unwrap().cache_reset()
MY_FUNC_2.lock().unwrap().cache_reset()
} |
Awesome! Thank you! |
I was wondering if there are plans to add functionality to clear caches programatically, or be able to force recomputation/defeat the cache on certain calls?
I'd love to contribute as I can, but I wanted to make sure this fit within the scope of what this crate intends to do. :)
The text was updated successfully, but these errors were encountered: