-
-
Notifications
You must be signed in to change notification settings - Fork 1
Invalidate cache
Ieuan Walker edited this page Apr 5, 2026
·
1 revision
You can invalidate endpoint caches programmatically.
- Add a tag to the endpoint cache
public class GetItemsEndpoint : IEndpointWithoutRequest<List<ItemModel>>
{
public static string CacheKey = "GetItemsEndpointCacheKey";
public static void Configure(RouteHandlerBuilder builder)
{
builder
.Get("/items")
.CacheOutput(TimeSpan.FromMinutes(5)).Tag(CacheKey);
}
public async Task<ItemModel> Handle(CancellationToken ct)
{
...
}
}- Invalidate the cache by injecting
IOutputCacheStore
public class PostItemEndpoint : IEndpointWithoutRequest<List<ItemModel>>
{
readonly IOutputCacheStore _outputCache;
public PostItemEndpoint(IOutputCacheStore outputCache)
{
_outputCache = outputCache ?? throw new ArgumentNullException(nameof(outputCache));
}
public static void Configure(RouteHandlerBuilder builder)
{
...
}
public async Task<ItemModel> Handle(CancellationToken ct)
{
...
await _outputCache.EvictByTagAsync(GetItemsEndpoint.CacheKey, default);
}
}Getting Started
Endpoints
- Endpoint interfaces
- HTTP verbs
- Request binding
- Grouping
- Returning multiple different responses
- Dependency injection
Validation
- Setup
- Data annotations
- Fluent validation
- Disabling validation
- Manually return BadRequest with validation errors
Output Caching
OpenAPI & Documentation