1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crateMacroArgs;
use ;
use TokenStream;
use ;
/// Define a memoized function
///
/// By default, it keeps the cache in memory unless you define `disk` or `redis`.
///
/// In the attribute list below, `size`, `eviction_policy` are possible just if it's a memory cache.
///
/// # Attributes
///
/// - `name`: (optional, string) Specify the name for the generated cache. Defaults to CONSTANT_CASE name of the function
/// - `size`: (optional, string) Specify to keep the number of entries in the cache. Default to unbounded.
/// - `eviction_policy`: (optional, string) Specify the eviction policy, valid options are "lfu" (Least Frequently Used) and "lru" (Least Recently Used). Defaults to "lfu".
/// - `ttl`: (optional, string) Specify a cache TTL in seconds. Defaults to unlimited amount of time.
/// - `key`: (optional, string) Specify a specific key to use. You need to define the following attributes for a custom `key`, e.g., `key(ty = "String", expr = r#"{ format!("{}:{}", arg1, arg2) }"#)`. By default, use all the arguments of the function as the key.
/// - `ty`: (string) Specify type of the key. E.g, `ty = "String"`
/// - `expr`: (string expr) Specify an expression used to generate a cache key.
/// E.g., `expr = r#"{ format!("{}:{}", arg1, arg2) }"#`.
/// - `result`: (optional) If your function returns a `Result`, only cache `Ok` values returned by the function. (Read the note below about `Result`)
/// - `option`: (optional) If your function returns an `Option`, only cache `Some` values returned by the function.
/// - `in_impl`: (optional) Set it if your function is defined in an `impl` block, otherwise not.
/// - `redis`: (optional) Store cached values in Redis.
/// - `prefix_block`: (optional, string expr) specify an expression used to create the string used as a
/// prefix for all cache keys of this function, e.g. `prefix_block = r#"{ "my_prefix:" }"#`.
/// When not specified, the cache prefix will be constructed from the name of the function. This
/// could result in unexpected conflicts between kash-functions of the same name, be sure to specify a
/// `prefix_block` if you have multiple kash-functions with the same name. And consider using a unique
/// separator at the end of the prefix, like ":" in the example above.
/// - `disk`: (optional) Store cached values on disk.
/// - `dir`: (optional, string) Specify directory of `disk` cache
/// - `sync_to_disk_on_cache_change`: (optional) Specify whether to synchronize the cache to disk each
/// time the cache changes.
/// - `connection_config`: (optional, string expr) Specify an expression which returns a `sled::Config`
/// to give more control over the connection to the `disk` cache, i.e., useful for controlling the rate at which the cache syncs to disk.
/// See the docs of `kash::stores::DiskCacheBuilder::connection_config` for more info.
///
/// # Note
///
/// - If your function returns a `Result`:
/// - In cases you define `result` in `kash`, the `Err` variant can be anything.
/// - But in cases you want to cache the `Err` variant too (by _not_ defining `result` in `kash`), the error type must be `Clone`able. So in this case, you may need to `Arc` your error type.
///