dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.46k stars 10.03k forks source link

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

Open Fear0 opened 1 month ago

Fear0 commented 1 month ago

Is there an existing issue for this?

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

TheEagleByte commented 1 month ago

+1 on this request.