Eviction
Eviction removes every entry in a namespace. You never name a key — that is the point of grouping entries under a namespace in the first place.
[HttpDelete("{id}")]
[ActionCacheEviction(Namespace = "Forecasts")]
public IActionResult Delete(int id) => Ok(_repository.Remove(id));When it runs
After the action, and only when the response was a success. An action that fails leaves the cache alone, so a failed write cannot throw away a cache that still matches the data.
Several namespaces at once
[ActionCacheEviction(Namespace = "Forecasts, Summaries")]Both groups are evicted on one successful response.
Per-resource eviction
With a route token in the namespace, eviction targets a single resource:
[HttpPut("{id}")]
[ActionCacheEviction(Namespace = "Account:{id}")]
public IActionResult Update(Guid id, AccountModel model) => Ok(_repository.Save(id, model));Updating account 42 clears Account:42 and leaves every other account’s entries in place.
Across layers
When several backends are registered, eviction reaches all of them. Key enumeration unions every layer, so an entry that exists only in the deepest store is still removed.
Minimal APIs
app.MapDelete("/forecasts", () => repository.Clear())
.WithActionCacheEviction("Forecasts");Chain the extension to invalidate more than one namespace from a single write:
app.MapDelete("/accounts/{id}", (int id) => repository.Remove(id))
.WithActionCacheEviction("Accounts")
.WithActionCacheEviction("Invoices");The attribute form cannot express this — [ActionCacheEviction] is single-use per action.
Every namespace named must be distinct, and none of them may be a namespace the same endpoint
caches into; see combining attributes.
Eviction during a refresh replay
Eviction is skipped on a refresh replay. An endpoint that carries both eviction and caching is replayed like any other, and evicting there would clear the very namespace the refresh pass is in the middle of warming — refresh would leave the cache emptier than it found it. Ordinary requests to that endpoint evict as normal.
Eviction or refresh?
Eviction is cheap and leaves the next reader to repopulate. Refresh costs more at write time and leaves the cache warm. Use eviction when reads are infrequent enough that a cold entry does not matter, or when the endpoint’s entries vary by request — which refresh skips anyway.