#[Cache]

Attribute on classes and methods.

use Saij\WpAppFramework\Cache\Cache;

Caches the output of a block (on a #[Block] class) or the response data of a REST route (on a #[RestRoute] method that answers only GET).

The entry depends on the inputs (block attributes, inner content and context values; URL parameters and arguments of a route), on the current value of each variant in vary and on the code. It expires after ttl seconds or when one of its tags is invalidated, whichever comes first.

Arguments

#[Cache(int $ttl, array $tags = [], array $vary = [])]
ParameterTypeDefaultDescription
ttlintrequiredLifetime in seconds, at least 1.
tagslist<CacheTag>[]Invalidate the entry: PostTypeTag, TaxonomyTag, SettingsTag or an enum of your own.
varylist<CacheVary>[]Circumstances the entry depends on, e.g. new UserVary() or new QueryParamVary('page').