-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresfeature-cachingIncludes: StackExchangeRedis and SqlServer distributed cachesIncludes: StackExchangeRedis and SqlServer distributed caches
Milestone
Description
Background and Motivation
The ASP.NET Core output caching middleware is great, but "limited" in terms of policy validation. Let's start with some code that you can write today in .NET 7:
builder.Services.AddOutputCache(options =>
{
options.AddPolicy("customPolicy", builder => builder.Expire(TimeSpan.FromSeconds(20)));
});
There is no way to validate that customPolicy actually exists. This is useful when configuring multiple routes from configuration such as is the case for YARP. See dotnet/yarp#2328
Proposed API
It would be preferred to something similar to IAuthorizationPolicyProvider implemented via DefaultAuthorizationPolicyProvider and ICorsPolicyProvider implemented via DefaultCorsPolicyProvider
namespace Microsoft.AspNetCore.OutputCaching;
+ public interface IOutputCachePolicyProvider
+ {
+ ValueTask<IOutputCachePolicy?> GetPolicyAsync(string policyName);
+ }
+
+ public class DefaultOutputCachePolicyProvider : IOutputCachePolicyProvider
+ {
+ private readonly OutputCacheOptions _options;
+
+ public DefaultOutputCachePolicyProvider(IOptions<OutputCacheOptions> options)
+ {
+
+ }
+
+ public ValueTask<IOutputCachePolicy?> GetPolicyAsync(string policyName)
+ {
+ options.NamedPolicies[policyName];
+ }
+ }OutputCacheOptions.NamedPolicies is internal hence this feature cannot be added in another library or the final application.
Usage Examples
Alternative Designs
None
Risks
None
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresfeature-cachingIncludes: StackExchangeRedis and SqlServer distributed cachesIncludes: StackExchangeRedis and SqlServer distributed caches