Attribute Macro cached::proc_macro::cached[][src]

#[cached]
Expand description

Attributes

  • Cache Name: Use name = "CACHE_NAME" to specify the name for the generated cache.
  • Cache Type: The default cache type is UnboundCache. You specify which of the built-in cache types to use with unbound, size = cache_size, and time = lifetime_in_seconds
  • Cache Create: You can specify the cache creation with create = "{ CacheType::new() }".
  • Custom Cache Type: You can use type = "CacheType" to specify the type of cache to use. This requires create to also be set.
  • Cache Key: Use key = "KeyType" to specify what type to use for the cache key. This requires convert to also be set.
  • Cache Key Convert: Use convert = "{ convert_inputs_to_key }". This requires either key or type to also be set.
  • Caching Result/Option: If your function returns a Result or Option you may want to use result or option to only cache when the output is Ok or Some
  • ** Indicating whether a result was cached ** Use with_cached_flag = true with a cached::Return<T> return type to have the macro set the was_cached flag on the cached::Return<T> result.

Note

The type, create, key, and convert attributes must be in a String This is because darling, which is used for parsing the attributes, does not support parsing attributes into Type or Block.