YARP Redis OutputCaching is not working. #2966
Answered
by
MihaZupan
RedEye-Developers
asked this question in
Q&A
-
public static IServiceCollection AddPresentation(this IServiceCollection service, IConfiguration config)
{
service.AddReverseProxy()
.LoadFromConfig(config.GetSection("ReverseProxy"))
.AddTransforms(context =>
{
if (!string.IsNullOrEmpty(context.Route.AuthorizationPolicy))
{
context.RequestTransforms.Add(context.Services.GetRequiredService<AddUserClaimsToHeadersTransform>());
}
});
return service;
}
public static IServiceCollection AddRedisOutputCache(this IServiceCollection service, IConfiguration config)
{
service.AddStackExchangeRedisOutputCache(x =>
{
x.InstanceName = "Redis";
x.Configuration = config[EnvKeys.Redis.DefaultConnection]!;
});
service.AddOutputCache(x =>
{
x.AddBasePolicy(builder => builder.Expire(TimeSpan.FromSeconds(10)));
x.AddPolicy("customPolicy", builder => builder.Expire(TimeSpan.FromMinutes(1)));
});
return service;
}
public static IApplicationBuilder UsePresentation(this IApplicationBuilder app)
{
app.UseHttpsRedirection();
app.UseRouting();
app.UseOutputCache();
app.UseAuthentication();
app.UseAuthorization();
return app;
}
public static WebApplication MapPresentation(this WebApplication app)
{
app.MapDefaultEndpointsForAspNetCore();
app.MapReverseProxy()
.CacheOutput();
return app;
}{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ReverseProxy": {
"Routes": {
"Reels_Route": {
"ClusterId": "Reels_Cluster",
"AuthorizationPolicy": "Reels-Service",
"OutputCachePolicy": "customPolicy",
"Match": {
"Path": "apis/reels/{**catch-all}"
},
"Transforms": [
{ "PathPattern": "{**catch-all}" }
]
}
},
"Clusters": {
"Reels_Cluster": {
"Destinations": {
"destination1": {
"Address": "http://localhost:5104"
}
}
}
}
}2025-10-16.19-12-41.mp4i have no idea what i did wrong, i follow the same instrection in this Docs and no logs about output-cache in console. |
Beta Was this translation helpful? Give feedback.
Answered by
MihaZupan
Oct 20, 2025
Replies: 1 comment
-
|
Looks like you're testing with authenticated requests?
You'd need a custom policy that takes auth into account. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
RedEye-Developers
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like you're testing with authenticated requests?
See https://learn.microsoft.com/en-us/aspnet/core/performance/caching/output?view=aspnetcore-9.0#default-output-caching-policy
You'd need a custom policy that takes auth into account.