Skip to content

[Container] Add OutputCache configuration from file #2883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

benjaminpetit
Copy link
Member

When using the YARP container, configuring middleware via dependency injection (DI) is not an option. This limitation makes it difficult to customize middleware behavior without modifying and rebuilding the container image.

In this PR, I added the possibility to configure output caching in the container configuration file.

@benjaminpetit benjaminpetit requested a review from MihaZupan as a code owner June 23, 2025 14:51
Copy link
Member

Choose a reason for hiding this comment

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

Should this be in the container assembly instead?
Long-term this is something that should likely be in ASP.NET instead of YARP.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's something I asked myself too, but I want to be able to reference these types in Aspire later...

I coud just duplicate the code for now in Aspire, that's a possibility. It would avoid the need of publishing a nuget package for that.

Copy link
Member

Choose a reason for hiding this comment

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

I suppose it's a question of whether we see this being valuable to YARP users outside of Aspire.
I don't have a problem with it shipping from YARP initially, we could always take the breaking change eventually if ASP.NET starts to include it.

Good point re: package update, if we're treating this as more experimental, then I think it'd be more flexible for us if we copy-paste it in Aspire instead, and keep it just in the container here for now.

/// <summary>
/// Collections of extensions to configure OutputCache
/// </summary>
public static class OutputCacheConfigExtensions
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I think we've mostly stuck with one type per file so far

Copy link
Member Author

Choose a reason for hiding this comment

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

Meh, we have modern IDE that supports multiple types per file. I think when the types are small and related, I find it easier to keep it together, if the file isn't big of course.

Copy link
Member

Choose a reason for hiding this comment

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

This type specifically should likely be in namespace Microsoft.Extensions.DependencyInjection (doesn't matter if it's not public)

@lqlive
Copy link

lqlive commented Jun 24, 2025

Hope you don't mind me asking - looking at this PR, it seems like dynamic operations on OutputCacheConfig (such as adding, modifying, or deleting configurations) aren't currently supported. Is this something that's been thought about?

/// <summary>
/// Configuration for <see cref="OutputCachePolicyBuilder"/>
/// </summary>
public sealed record NamedCacheConfig
Copy link
Member

Choose a reason for hiding this comment

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

We should either move this to a more nested namespace, or name this NamedOutputCacheConfig, just cache config is too generic for Yarp.ReverseProxy.Configuration IMO.

Copy link
Member

Choose a reason for hiding this comment

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

I suppose it's a question of whether we see this being valuable to YARP users outside of Aspire.
I don't have a problem with it shipping from YARP initially, we could always take the breaking change eventually if ASP.NET starts to include it.

Good point re: package update, if we're treating this as more experimental, then I think it'd be more flexible for us if we copy-paste it in Aspire instead, and keep it just in the container here for now.

/// <summary>
/// Collections of extensions to configure OutputCache
/// </summary>
public static class OutputCacheConfigExtensions
Copy link
Member

Choose a reason for hiding this comment

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

This type specifically should likely be in namespace Microsoft.Extensions.DependencyInjection (doesn't matter if it's not public)

Comment on lines +89 to +91
Assert.NotNull(test1);
Assert.NotNull(test2);
Assert.NotNull(test3);
Copy link
Member

Choose a reason for hiding this comment

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

I take it there's no good way to assert that the relevant properties were applied correctly?

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.

3 participants