Skip to content

Commit 30d4ec4

Browse files
kjacelit0451
andauthored
Prevent Delivery API output cache configuration from affecting other controllers (#17405)
Co-authored-by: Elitsa <[email protected]>
1 parent 7542764 commit 30d4ec4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.AspNetCore.OutputCaching;
2+
3+
namespace Umbraco.Cms.Api.Delivery.Caching;
4+
5+
internal sealed class NoOutputCachePolicy : IOutputCachePolicy
6+
{
7+
ValueTask IOutputCachePolicy.CacheRequestAsync(OutputCacheContext context, CancellationToken cancellationToken)
8+
{
9+
context.EnableOutputCaching = false;
10+
11+
return ValueTask.CompletedTask;
12+
}
13+
14+
ValueTask IOutputCachePolicy.ServeFromCacheAsync(OutputCacheContext context, CancellationToken cancellationToken)
15+
=> ValueTask.CompletedTask;
16+
17+
ValueTask IOutputCachePolicy.ServeResponseAsync(OutputCacheContext context, CancellationToken cancellationToken)
18+
=> ValueTask.CompletedTask;
19+
}

src/Umbraco.Cms.Api.Delivery/DependencyInjection/UmbracoBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private static IUmbracoBuilder AddOutputCache(this IUmbracoBuilder builder)
105105

106106
builder.Services.AddOutputCache(options =>
107107
{
108-
options.AddBasePolicy(_ => { });
108+
options.AddBasePolicy(build => build.AddPolicy<NoOutputCachePolicy>());
109109

110110
if (outputCacheSettings.ContentDuration.TotalSeconds > 0)
111111
{

0 commit comments

Comments
 (0)