Crates.io | cache-this |
lib.rs | cache-this |
version | 0.1.2 |
source | src |
created_at | 2023-11-14 22:04:22.613672 |
updated_at | 2024-04-03 21:52:08.780756 |
description | Macro for simple caching of expression using the file system |
homepage | https://github.com/DerMagischeBier/cache-this |
repository | https://github.com/DerMagischeBier/cache-this |
max_upload_size | |
id | 1035498 |
size | 6,022 |
Macro for simple caching of expressions using the local file system. The expression within
the cache_this
macro will be executed only if no cached result is already locally present. If
no result is present, yet it will be saved to the local file system and subsequently used.
Results are even cached in between program execution enabling rapid prototyping by getting rid of long execution times per iteration.
Expressions are cached by their token representation. cache_this!
does not recognize changes to
expression results. To remove the cached values delete the .cache-this
folder.
Note that, for serializing and deserializing cache_this!
relies on serde_json
. Thus,
cache_this!
requires to be cached expression results to implement the needed traits.
use cache_this::cache_this;
fn main() {
// `some_long_running_function` will be executed here once
let result = cache_this!(some_long_running_function());
//...
// in following calls the cached result will be read without
// executing the function
some_other_method(cache_this!(some_long_running_function()));
}