Skip to content

Add output cache policy for authenticated responses#79

Merged
IeuanWalker merged 4 commits intomasterfrom
OutputCaching
Jan 27, 2026
Merged

Add output cache policy for authenticated responses#79
IeuanWalker merged 4 commits intomasterfrom
OutputCaching

Conversation

@IeuanWalker
Copy link
Owner

Introduces AllowAuthenticatedCachePolicy to enable safe output caching of authenticated responses in Minimal APIs. Adds an extension method to OutputCachePolicyBuilder for easy registration.

Introduces AllowAuthenticatedCachePolicy to enable safe output caching of authenticated responses in Minimal APIs. Adds an extension method to OutputCachePolicyBuilder for easy registration. Ensures only 200 OK responses without Set-Cookie headers are cached. Applies [ExcludeFromCodeCoverage] to new and updated classes.
@IeuanWalker IeuanWalker requested a review from Copilot January 27, 2026 10:38
@IeuanWalker IeuanWalker marked this pull request as ready for review January 27, 2026 10:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces output caching capabilities for authenticated responses in Minimal APIs by adding a new AllowAuthenticatedCachePolicy class and a corresponding extension method AllowCachingAuthenticatedResponses() for OutputCachePolicyBuilder. The implementation provides basic output caching that prevents caching of responses with cookies or non-200 status codes.

Changes:

  • Added AllowAuthenticatedCachePolicy implementing IOutputCachePolicy to control cache behavior based on response characteristics
  • Added OutputCachePolicyBuilderExtensions with AllowCachingAuthenticatedResponses() method for easy policy registration
  • Added [ExcludeFromCodeCoverage] attribute to RouteHandlerBuilderExtensions (housekeeping)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/IeuanWalker.MinimalApi.Endpoints/AllowAuthenticatedCachePolicy.cs New output cache policy implementation that enables caching for 200 OK responses without Set-Cookie headers
src/IeuanWalker.MinimalApi.Endpoints/Extensions/OutputCachePolicyBuilderExtensions.cs New extension method to register the cache policy with OutputCachePolicyBuilder
src/IeuanWalker.MinimalApi.Endpoints/Extensions/RouteHandlerBuilderExtensions.cs Added [ExcludeFromCodeCoverage] attribute to match other extension classes in the project

Added detailed XML documentation comments to extension methods across the IeuanWalker.MinimalApi.Endpoints namespace. This improves code readability and enhances IntelliSense by describing method purposes, parameters, type parameters, return values, and exceptions. No functional changes were made.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Updated the comment to specify that only successful 200 OK responses are cached, removing the ambiguous "by default" wording. No changes were made to the caching logic itself.
Updated Dictionary initializations to use C# collection expression syntax ([]) for brevity and clarity. Removed unnecessary IDE0130 pragma directives and streamlined the namespace declaration in AllowAuthenticatedCachePolicy.cs.
@IeuanWalker IeuanWalker merged commit 262f4bd into master Jan 27, 2026
1 check passed
@IeuanWalker IeuanWalker deleted the OutputCaching branch January 27, 2026 11:13
@github-actions
Copy link

Summary

Summary
Generated on: 1/27/2026 - 11:15:07 AM
Coverage date: 1/27/2026 - 11:14:59 AM - 1/27/2026 - 11:15:02 AM
Parser: MultiReport (4x Cobertura)
Assemblies: 3
Classes: 83
Files: 70
Line coverage: 90.1% (5172 of 5735)
Covered lines: 5172
Uncovered lines: 563
Coverable lines: 5735
Total lines: 9769
Branch coverage: 83% (2450 of 2949)
Covered branches: 2450
Total branches: 2949
Method coverage: Feature is only available for sponsors
Tag: 396_21394967102

Coverage

ExampleApi - 97%
Name Line Branch
ExampleApi 97% 78.5%
ExampleApi.Data.InMemoryTodoStore 100% 100%
ExampleApi.EndpointExtensions 95.6%
ExampleApi.Endpoints.Enum.PostFromBody.RequestModelValidator 100%
ExampleApi.Endpoints.FileHandling.PostListOfFiles.PostFileHandlingListOfFil
esEndpoint
100%
ExampleApi.Endpoints.FileHandling.PostMultipart.PostFileHandlingMultipartEn
dpoint
100% 66.6%
ExampleApi.Endpoints.FileHandling.PostSingleFile.PostFileHandlingSingleFile
Endpoint
100%
ExampleApi.Endpoints.Todos.Delete.DeleteTodoEndpoint 100%
ExampleApi.Endpoints.Todos.GetAll.GetAllTodosEndpoint 100%
ExampleApi.Endpoints.Todos.GetById.GetTodoByIdEndpoint 100% 100%
ExampleApi.Endpoints.Todos.GetExport.GetExportEndpoint 100% 83.3%
ExampleApi.Endpoints.Todos.Patch.PatchTodoEndpoint 100% 100%
ExampleApi.Endpoints.Todos.Post.PostTodoEndpoint 100%
ExampleApi.Endpoints.Todos.Post.RequestModelValidator 100%
ExampleApi.Endpoints.Todos.Post.ResponseModel 100%
ExampleApi.Endpoints.Todos.Put.PutTodoEndpoint 100% 100%
ExampleApi.Endpoints.TypeExamples.TypeExamplesEndpointGroup 100%
ExampleApi.Endpoints.Validation.GetDataAnnotationsFromQuery.GetFluentValida
tionFromQuery
0%
ExampleApi.Endpoints.Validation.GetFluentValidationFromQuery.GetFluentValid
ationFromQuery
0%
ExampleApi.Endpoints.Validation.GetFluentValidationFromQuery.RequestModelVa
lidator
98% 0%
ExampleApi.Endpoints.Validation.GetValidationErrors.GetValidationErrorsEndp
oint
100%
ExampleApi.Endpoints.Validation.PostDataAnnotationsFromBody.PostDataValidat
ionEndpoint
0%
ExampleApi.Endpoints.Validation.PostFluentValidation.NestedObjectModelValid
ator
100% 50%
ExampleApi.Endpoints.Validation.PostFluentValidation.PostFluentValidationEn
dpoint
0%
ExampleApi.Endpoints.Validation.PostFluentValidation.RequestModelValidator 100% 100%
ExampleApi.Endpoints.Validation.PostFluentValidationFromFrom.PostFluentVali
dationFromFromEndpoint
0%
ExampleApi.Endpoints.WeatherForecast.Get.V1.GetWeatherForecastEndpoint 100%
ExampleApi.Endpoints.WeatherForecast.Get.V2.GetWeatherForecastEndpoint 100%
Program 100%
IeuanWalker.MinimalApi.Endpoints - 87.2%
Name Line Branch
IeuanWalker.MinimalApi.Endpoints 87.2% 82.1%
IeuanWalker.MinimalApi.Endpoints.Extensions.StringExtensions 100% 100%
IeuanWalker.MinimalApi.Endpoints.Filters.FluentValidationFilter`1 100% 100%
IeuanWalker.MinimalApi.Endpoints.FluentValidationEnumExtensions 100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.AuthorizationP
oliciesAndRequirementsOperationTransformer
100% 92.3%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Core.EndpointRequestTypeMapper
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Core.OpenApiPathMatcher
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Core.OpenApiSchemaHelper
97% 93%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Core.SchemaConstants
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Core.SchemaTypeResolver
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.EnumSchemaTransformer
100% 90%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.NullableSchemaReorderTransformer
100% 93.2%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.TypeDocumentTransformer
95% 90.7%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.UnusedComponentsCleanupTransformer
91.7% 83.6%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.AlterOperation
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.CustomRule`1
100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.DescriptionRule
100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.EmailRule
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.EnumRule
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.PatternRule
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.PropertyValidationBuilder`2
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.RangeRule`1
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.RemoveAllOperation
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.RemoveOperation
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.RequiredRule
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.StringLengthRule
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.UrlRule
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.ValidationConfiguration`1
100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.ValidationConfigurationBuilder`1
97.4% 85.2%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.ValidationMetadata`1
100% 50%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.PropertyEnhanc
er.Validation.ValidationRule
100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.RequestPropert
yEnhancer.ValidationDocumentTransformer
74.5% 69.4%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.SecurityScheme
Transformer
100% 100%
IeuanWalker.MinimalApi.Endpoints.OpenApiDocumentTransformers.SecurityScheme
TransformerOptions
100%
IeuanWalker.MinimalApi.Endpoints.OpenApiExtensions 93.1% 100%
IeuanWalker.MinimalApi.Endpoints.ValidationErrors`1 98.2% 95.8%
IeuanWalkerMinimalApiEndpoints.EndpointExtensions 0%
IeuanWalker.MinimalApi.Endpoints.Generator - 95.9%
Name Line Branch
IeuanWalker.MinimalApi.Endpoints.Generator 95.9% 88.8%
IeuanWalker.MinimalApi.Endpoints.Generator.AbstractValidatorInfo 100%
IeuanWalker.MinimalApi.Endpoints.Generator.Block 100% 100%
IeuanWalker.MinimalApi.Endpoints.Generator.CachableLocation 100% 83.3%
IeuanWalker.MinimalApi.Endpoints.Generator.DiagnosticInfo 100%
IeuanWalker.MinimalApi.Endpoints.Generator.EndpointGenerator 98.2% 86.7%
IeuanWalker.MinimalApi.Endpoints.Generator.EndpointGroupInfo 100%
IeuanWalker.MinimalApi.Endpoints.Generator.EndpointInfo 100%
IeuanWalker.MinimalApi.Endpoints.Generator.Extensions.SourceGeneratorExtens
ions
100% 92.3%
IeuanWalker.MinimalApi.Endpoints.Generator.Extensions.StringExtensions 100% 100%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.EndpointGeneratorHelpers 95.8% 95.6%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.HttpVerbRouteHelpers 93.6% 85.7%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.MapGroupHelpers 88.4% 78.8%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.RequestBindingTypeHelper
s
95.8% 92.6%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.ValidationHelpers 94.8% 90.9%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.WithNameHelpers 100% 91.6%
IeuanWalker.MinimalApi.Endpoints.Generator.Helpers.WithTagsHelpers 94.3% 91.9%
IeuanWalker.MinimalApi.Endpoints.Generator.IndentedTextBuilder 100%
IeuanWalker.MinimalApi.Endpoints.Generator.TypeInfo 100%
IeuanWalker.MinimalApi.Endpoints.Generator.ValidatorInfo 100%

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants