Cache Policies and Invalidation
Control cache lifetime and tags.
Named Policies
Rather than repeating cache settings on every endpoint, define reusable named policies once and reference them by name.
builder.Services.AddOutputCache(options =>
{
options.AddPolicy("Short", policy =>
policy.Expire(TimeSpan.FromSeconds(10)));
options.AddPolicy("Long", policy =>
policy.Expire(TimeSpan.FromMinutes(10)));
});Applying a Named Policy
Reference the policy by its name when caching an endpoint.
app.MapGet("/catalog", GetCatalog)
.CacheOutput("Long");All lessons in this course
- Rate Limiting Algorithms
- Configuring Rate Limiting Middleware
- Output Caching Basics
- Cache Policies and Invalidation