dotnet / dotnet/aspnetcore

Is there a way to evict a cache entry by value in addition to evicting by tag - OutputCaching Asp.Net Core

Open
#57,850 4 comments 12 reactions 0 assignees View on GitHub
area-middleware feature-output-caching
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

Hi,

I am using Output Caching with Redis in my .NET 8 web API. The IOutputCacheStore API only provides a method for evicting cache by tags and not by cache keys. This is limiting, as the Tag() method in the CacheOutput fluent API chain only accepts strings as parameters and does not allow for delegates, unlike the VaryByValue() method, where we can access the HttpContext and query parameters to dynamically create cache keys. As a result, it's not possible to dynamically create a tag in the same way as in VaryByValue() to use as input for the EvictByTag() method.

I have overridden the caching policy to allow output caching of authenticated requests, enabling me to cache by an ID value (e.g., user ID) and evict the cache entry associated with that specific value.

Is there a way to address this issue, allowing more granular cache eviction by user or query parameter, without having to evict the entire cache for the endpoint in ASP.NET Core Output Caching?

### Describe the solution you'd like

An fluent api that allows evicting cache entries by value in Asp.Net Core OutputCaching

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.