https://github.com/vurv78/mincache
Minimal crate to cache return values of your function returns.
https://github.com/vurv78/mincache
cache function memoize minimal rust
Last synced: over 1 year ago
JSON representation
Minimal crate to cache return values of your function returns.
- Host: GitHub
- URL: https://github.com/vurv78/mincache
- Owner: Vurv78
- License: mit
- Created: 2022-04-24T02:17:29.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-04-24T02:24:18.000Z (about 4 years ago)
- Last Synced: 2025-02-08T02:35:41.949Z (over 1 year ago)
- Topics: cache, function, memoize, minimal, rust
- Language: Rust
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ``mincache``
Minimal crate to cache return values of your function returns.
Currently only supports a timer / cooldown cache.
## Example
```rs
pub use mincache::timed;
// "fmt" is what you'd put after core::time::Duration::from_<>. E.g. "secs", "millis", "nanos", etc.
#[timed(t = 5000, fmt = "millis"/*, reference = true*/)]
pub fn func(x: i32) -> std::time::Instant {
println!("This will print once {x}");
// Reference non-cached self.
// inner_func(x);
// This value will be cloned each time this is called before the cooldown is over
// If you want to instead pass a reference, look into mincache/tests/ref.rs
// (just add ``reference = true`` to the attribute params)
std::time::Instant::now()
}
fn main() {
// Will call the function a single time.
for _ in 0..1000000 {
let _xyz = func(55);
}
}
```