cache_this/
lib.rs

1//! Macro for simple caching of expressions using the local file system. The expression within
2//! the `cache_this` macro will be executed only if no cached result is already locally present. If
3//! no result is present yet it will be saved to the local file system and subsequently used.
4//!
5//! Results are even cached in between program execution enabling rapid prototyping by getting rid
6//! of long execution times per iteration.
7//!
8//! Expression are cache by their token representation. `cache_this!` does not recognize changes to
9//! expression results. To remove the cached values delete the `.cache-this` folder.
10//!
11//! Note that, for serializing and deserializing `cache_this!` relies on `serde_json`. Thus,
12//! `cache_this!` requires to be cached expression results to implement the needed traits.
13//!
14//! # Example
15//! ```rust
16//! # use cache_this::cache_this;
17//! # fn some_long_running_function() -> u8 {0u8}
18//! /// `some_long_running_function` will be executed here once
19//! let result = cache_this!(some_long_running_function());
20//! # assert_eq!(0u8, result);
21//! ///...
22//! /// in following calls the cached result will be read without
23//! /// executing the function
24//! # fn some_other_method(a : u8) {}
25//! some_other_method(cache_this!(some_long_running_function()));
26//!
27//! # std::fs::remove_dir_all(".cache-this").unwrap()
28//! ```
29
30/// `cache_this` macro enabling easy caching of expressions
31pub use cache_this_proc_macro::cache_this;
32
33#[doc(hidden)]
34pub use ::serde_json::{to_string, from_str};