Caching structures and simplified function memoization, using #[kash]/#[io_kash] macros.
use kash;
/// Defines a function named `fib` that uses a cache implicitly named `FIB`.
/// By default, the cache will be the function's name in all caps.
Or if you want to limit the size and time-to-live:
use kash;
const TTL: u64 = 1000;
Features
default: Includesahashfeaturesahash: Enableahashhasher as default hashing algorithm.async: Include support for async functionsredis_store: Include Redis cache storeredis_async_std: Include async Redis support usingasync-stdandasync-stdtls support, impliesredis_storeandasyncredis_tokio: Include async Redis support usingtokioandtokiotls support, impliesredis_storeandasyncredis_connection_manager: Enable the optionalconnection-managerfeature ofredis. Any async redis caches created will use a connection manager instead of aMultiplexedConnectionredis_ahash: Enable the optionalahashfeature ofredisdisk_store: Include disk cache store
use sleep;
use Duration;
use kash;
/// Use an explicit cache-type with a custom creation block and custom cache-key generating block
use io_kash;
use AsyncRedisCache;
use Error;
/// Cache the results of an async function in redis. Cache
/// keys will be prefixed with `cache_redis_prefix`.
/// A `map_error` closure must be specified to convert any
/// redis cache errors into the same type of error returned
/// by your function. All `io_kash` functions must return `Result`s.
async
use io_kash;
use DiskCache;
use Error;
/// Cache the results of a function on disk.
/// Cache files will be stored under the system cache dir
/// unless otherwise specified with `disk_dir` or the `create` argument.
/// A `map_error` closure must be specified to convert any
/// disk cache errors into the same type of error returned
/// by your function. All `io_kash` functions must return `Result`s.
Functions defined via macros will have their result, cached using the
function's arguments as a key, a convert expression specified.
When a macro-defined function is called, the function's cache is first checked for an already computed (and still valid) value before evaluating the function body.
See examples directory for more examples.
Thanks
This project is a clone of https://github.com/jaemk/cached repository
License: MIT