Declarative read-through caching for Ash read and generic actions. See
AshCache.Resource for the DSL and README.md in this directory for the design.
These helpers are the runtime escape hatch for operational situations (a support task, a migration) that need to reach past the declarative layer.
Telemetry
Seven :telemetry events let you assert cache behaviour in tests and
measure hit rates in production. All have empty measurements. Calls that
are bypassed, or not cached, emit nothing. Actor and tenant are never in
the metadata.
[:ash_cache, :read, :hit]- a cached read was answered without the data layer: from the store, or with the records of an identical read running at the same time (seeAshCache.Coalesce). Metadata::resource,:action,:store.[:ash_cache, :read, :miss]- a cached read was not in the store and went to the data layer. Metadata::resource,:action,:store, and:error, which isnilnormally or the reason when the store failed to answer (the read still goes through).[:ash_cache, :action, :hit]and[:ash_cache, :action, :miss]- the same for a cached generic action, with the same metadata. A miss means the action'srunwas called.[:ash_cache, :calculation, :hit]and[:ash_cache, :calculation, :miss]- the same for one record of a cached calculation (seeAshCache.Calculations.CalculateThrough), with:calculationin place of:action. A miss means the calculation ran for that record.[:ash_cache, :invalidate]- a resource's cache was invalidated, by a successful create, update or destroy or byinvalidate/1. Metadata::resource,:store.
Summary
Functions
Clears a whole store, including other resources' entries.
Invalidates every cached read and generic action of a resource, exactly like a successful write does.
Functions
Clears a whole store, including other resources' entries.
@spec invalidate(Ash.Resource.t()) :: :ok | {:error, term()}
Invalidates every cached read and generic action of a resource, exactly like a successful write does.