Skip to content

v11 update: IOutputCachePolicyProvider interface #37719

Description

@wadepickett

Note

This is an AI-assisted coverage analysis generated by wadepickett

Target repository: dotnet/AspNetCore.Docs
Analyzed at commit: 4986136881f2bbf1879f10106467769df5a49932
Product source verified at: dotnet/aspnetcore @ 1fcd7ef305697a1888f3ede076010350ae9f4f8d
Source release note: IOutputCachePolicyProvider interface


🎯 Goal

Tell a reader of the output caching article that .NET 11 exposes IOutputCachePolicyProvider as the policy-resolution seam behind output caching. The article already explains built-in named policies, base policies, and custom IOutputCachePolicy implementations; this report closes the residual gap for dynamic policy providers that load policies from external configuration, databases, or tenant-specific sources.

Gaps this report closes:

  1. The output caching article never names the new IOutputCachePolicyProvider interface or its two members.
  2. The article doesn't explain that a custom provider can replace the default provider through dependency injection when named and base policies must be resolved dynamically.

✅ Coverage status summary

Legend: ✅ already documented · ✏️ update needed · 🟣 could not determine

# Feature element from What's New Status Where
1 IOutputCachePolicyProvider is a new public output-caching policy provider interface ✏️ 1. Update — performance/caching/output.md L73–L79
2 GetBasePolicies() returns the base policies to apply to requests ✏️ 1. Update — same section
3 GetPolicyAsync(string policyName) resolves named policies dynamically ✏️ 1. Update — same section
4 Built-in OutputCacheOptions.AddPolicy and AddBasePolicy still configure the default provider ✅ performance/caching/output.md L55–L77 and product source OutputCacheOptions.cs L39–L104
5 Custom IOutputCachePolicy implementations can still be authored and selected ✅ performance/caching/output.md L92–L127

🔢 Version applicability

Applies to: CURRENT-ONLY
Target moniker: >= aspnetcore-11.0
Earlier versions affected: None — IOutputCachePolicyProvider is in PublicAPI.Unshipped.txt for .NET 11, while IOutputCachePolicy and the OutputCacheOptions policy methods were already shipped.

Article monikerRange Moniker state
performance/caching/output.md '>= aspnetcore-7.0' State D — the insertion point after L77 sits inside the broader >= aspnetcore-8.0 body zone (L18–L262). Add the provider section by closing >= aspnetcore-8.0, opening >= aspnetcore-11.0, adding the content, closing it, and reopening >= aspnetcore-8.0. The included .NET 7 article (performance/caching/output/includes/output7.md) remains unchanged.

The article has no tab groups, so the moniker split carries no tab-nesting hazard. After the change, output.md should have 3 :::moniker range= openers and 3 :::moniker-end closers; the reopened >= aspnetcore-8.0 range must be copied exactly.


📋 Coverage gap summary

A developer reading performance/caching/output.md can learn how to define named policies and base policies in OutputCacheOptions, and can author custom IOutputCachePolicy classes. They can't learn the new .NET 11 seam that controls where those policies come from: IOutputCachePolicyProvider. That matters for the scenarios named in the release note — external configuration, databases, and tenant-specific policy rules — because those scenarios don't fit static AddPolicy calls in Program.cs.

Feature announced in What's New:

ASP.NET Core in .NET 11 provides the IOutputCachePolicyProvider interface for implementing custom output caching policy selection logic. By using this interface, apps can determine the default base caching policy, check for the existence of named policies, and support advanced scenarios where policies must be resolved dynamically. Examples include loading policies from external configuration sources, databases, or applying tenant-specific caching rules.

Product source confirms the new seam: AddOutputCache registers DefaultOutputCachePolicyProvider as IOutputCachePolicyProvider, the middleware asks the provider for base policies, and named policies resolve through the provider at request time.

Breaking change: No — new public interface with the existing options-based behavior preserved by the default provider.


📁 Affected files

Item Path Lines Section
1. performance/caching/output.md after 77 "Configure multiple endpoints or pages"

Target article uids: performance/caching/output


📝 Proposed changes

✏️ 1. Update — performance/caching/output.md, split the moniker zone and insert after line 77

Applies to: >= aspnetcore-11.0
Location: Lines 73–79, immediately after the paragraph beginning "For Razor Pages apps" and before ## Work with the default output caching policy.

Before (lines 73–79):

For apps with controllers, apply the `[OutputCache]` attribute to the action method to select a policy:

:::code language="csharp" source="~/performance/caching/output/samples/9.x/OCControllers/Controllers/Expire20Controller.cs" id="snippet_selectpolicy":::

For Razor Pages apps, apply the attribute to the Razor page class.

## Work with the default output caching policy

After:

For apps with controllers, apply the `[OutputCache]` attribute to the action method to select a policy:

:::code language="csharp" source="~/performance/caching/output/samples/9.x/OCControllers/Controllers/Expire20Controller.cs" id="snippet_selectpolicy":::

For Razor Pages apps, apply the attribute to the Razor page class.

:::moniker-end

:::moniker range=">= aspnetcore-11.0"

### Resolve policies dynamically with `IOutputCachePolicyProvider`

In .NET 11 or later, implement <xref:Microsoft.AspNetCore.OutputCaching.IOutputCachePolicyProvider> when policy selection needs to come from a dynamic source, such as external configuration, a database, or tenant-specific rules. The provider supplies the base policies for a request and resolves named policies used by endpoint metadata:

```csharp
public sealed class TenantOutputCachePolicyProvider : IOutputCachePolicyProvider
{
    public IReadOnlyList<IOutputCachePolicy> GetBasePolicies()
    {
        // Return the default policies to apply to every request.
        return [new TenantBasePolicy()];
    }

    public ValueTask<IOutputCachePolicy?> GetPolicyAsync(string policyName)
    {
        // Resolve named policies dynamically, for example from configuration or a database.
        IOutputCachePolicy? policy = ResolvePolicy(policyName);
        return ValueTask.FromResult(policy);
    }
}
```

Register the custom provider in dependency injection after calling `AddOutputCache`:

```csharp
builder.Services.AddOutputCache();
builder.Services.AddTransient<IOutputCachePolicyProvider, TenantOutputCachePolicyProvider>();
```

The built-in provider continues to use policies configured with `OutputCacheOptions.AddPolicy` and `AddBasePolicy`. Replace it only when named or base policies must be resolved outside the static options configuration.

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

## Work with the default output caching policy

Rationale: The policy-selection seam belongs next to the existing policy configuration section, where a reader is already deciding between base policies, named policies, and custom policy implementations. The text is scoped to >= aspnetcore-11.0 because the interface is new in .NET 11; the surrounding output caching content remains available for >= aspnetcore-8.0.


✅ 2. Update — TOC

No TOC change required. The edit adds a subsection to an article that already has a TOC entry; no new article is proposed.


✅ Action plan

  1. Confirm the coverage status summary — especially that existing IOutputCachePolicy and OutputCacheOptions policy coverage doesn't already cover provider replacement.
  2. Apply change 1 as a State D four-directive split. Verify moniker balance: 3 :::moniker range= openers and 3 :::moniker-end closers in output.md, with the reopened >= aspnetcore-8.0 range copied character-for-character.
  3. Verify the <xref:Microsoft.AspNetCore.OutputCaching.IOutputCachePolicyProvider> reference resolves after API docs publish for .NET 11.
  4. Build and confirm the new section renders only under the .NET 11 selector and does not appear under .NET 7–10.
  5. Resolve any OpenPublishing.Build warnings.

⚠️ Review considerations

  • 🟣 Concrete sample shape. Product source verifies the interface and DI replacement seam, but the proposed TenantOutputCachePolicyProvider is illustrative. A product-team reviewer should decide whether to include a full compiling sample or keep the section conceptual until API docs for IOutputCachePolicyProvider publish.
  • False-positive search result excluded: security/authorization/custom-authorization-policy-providers.md covers IAuthorizationPolicyProvider, not output caching. It shouldn't be linked from this issue.

🔗 References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions