persistentcache-rs
persistentcache-rs implements the macros cache!
and cache_func!
and the procedural macro #[peristent_cache]
to cache function calls or entire functions.
The implemented storages are persistent and can be shared between processes.
Storages either store on disk (FileStorage
) or Redis (RedisStorage
).
The documentation and examples can be found here.
Example
Here is an example using the #[peristent_cache]
procedural macro:
extern crate lazy_static;
extern crate persistentcache;
extern crate persistentcache_procmacro;
use *;
use ;
use persistent_cache;
// Either store it in a `FileStorage`...
// ... or in a `RedisStorage`
This will print:
Calculating 2 + 2...
4
4
Calculating 3 + 2...
5
5
History
This crate is inspired by owls-cache and its primary goal is to teach myself Rust.
While working on it, I realised that a similar crate already exists: cached-rs.
I've borrowed a couple of ideas from there.
I suggest you have a look at the cached-rs crate, too.
Unfortunately it lacks the 'persistent' part and the caches cannot be shared between processes/threads, but it should be fairly easy to extend it.
Furthermore, the excellent accel has been very helpful. I shamelessly copied parts of it for the persistentcache_procmacro
crate.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.