Comments (7)
That's certainly something that could be added in some capacity! Maybe adding a Cached::cache_reset
trait method? I'd be a little hesitant to add that logic into the macro though since you could manually grab a lock and mutate the cache from within the cached!
function:
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);
}
}
from cached.
@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.
from cached.
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
from cached.
added in #14
from cached.
Is there a way to use this functionality in combination with the proc-macro
?
from cached.
@emirror-de the cache_clear
and cache_reset
methods are available on cache types. Which macro was used doesn't matter. The proc macros will generate a global identifier either equal to the name
argument passed to the macro or equal to the function name uppercased.
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()
}
from cached.
Awesome! Thank you!
from cached.
Related Issues (20)
- Cannot call *_no_cache function HOT 3
- `failed to resolve: could not find `async_sync` in `cached`` HOT 2
- Once with sync_writes and async causes deadlocks in tokio.
- Unnecessary `&mut V` with `get_or_set_with` and `try_get_or_set_with` (CachedAsync)
- Feature: Ability to configure (or reconfigure) a SizedCache `size` based on runtime data HOT 4
- 2021 edition?
- Async disk cache HOT 4
- Add helper attribute to ignore arguments HOT 1
- Disk Cache does not persist between runs HOT 1
- Borrowed keys and values for `IOCached::set_cache` HOT 1
- Cache clear operation
- proc_macro: support args which are &T and Option<&T>
- [Question] Thread safety? HOT 3
- Redis cache doesn't support patterns HOT 1
- DiskCache blobs aren't cleaned on overwrite HOT 8
- Why does `DiskCache` need to impl `Display`? HOT 6
- [Discussion] What do you think of removing `async-std` support?
- Cache hit / miss rate metrics when using `cached` procedural macro HOT 3
- Generic parameters not added to no_cache function.
- Replace instant (unmaintained) by something else HOT 3
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 cached.