Attribute Macro cached::proc_macro::once

source ·
#[once]
Available on crate feature proc_macro only.
Expand description

Define a memoized function using a cache store that implements cached::Cached (and cached::CachedAsync for async functions). Function arguments are not used to identify a cached value, only one value is cached unless a time expiry is specified.

§Attributes

  • name: (optional, string) specify the name for the generated cache, defaults to the function name uppercase.
  • time: (optional, u64) specify a cache TTL in seconds, implies the cache type is a TimedCached or TimedSizedCache.
  • sync_writes: (optional, bool) specify whether to synchronize the execution of writing of uncached values.
  • result: (optional, bool) If your function returns a Result, only cache Ok values returned by the function.
  • option: (optional, bool) If your function returns an Option, only cache Some values returned by the function.
  • with_cached_flag: (optional, bool) If your function returns a cached::Return or Result<cached::Return, E>, the cached::Return.was_cached flag will be updated when a cached value is returned.