cached
simple rust caching macro
Easy to use function caching/memoization inspired by python decorators.
Function results are cached using the function's arguments as a key.
When a cached!
defined function is called, the function's cache is first checked for an already
computed (and still valid) value before evaluating the function body.
Due to the requirements of storing arguments and return values in a global cache,
function arguments and return types must be owned, function arguments must implement Hash + Eq + Clone
,
and function return types must implement Clone
.
Arguments and return values will be cloned
in the process of insertion and retrieval.
cached!
functions should not be used to produce side-effectual results!
See examples
for example of implementing a custom cache-store.
Usage
extern crate cached;
// `cached!` macro requires the `lazy_static!` macro
extern crate lazy_static;
use ;
use sleep;
use SizedCache;
cached!