Skip to content
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

Proposal: further tags for output cache #8641

Open
MatteoPiovanelli-Laser opened this issue Dec 22, 2022 · 4 comments
Open

Proposal: further tags for output cache #8641

MatteoPiovanelli-Laser opened this issue Dec 22, 2022 · 4 comments
Milestone

Comments

@MatteoPiovanelli-Laser
Copy link
Contributor

Tags = new[] { _invariantCacheKey }.Union(cacheItemTags.Distinct()).ToArray(),

OutputCache is currently using the Ids of the displayed ContentItems as tags for the OutputCache.
In a few of our applications, we've found this somewhat limiting, so we've had to find workarounds, in cases where a content that isn't, strictly speaking, being displayed nonetheless is relevant to what should be shown, and a change in its state should cause the output cache to be evicted. A common example would be some setting or configuration item.

We propose adding an interface allowing injection of additional tags, so it's easier for features to control the eviction of elements from output cache.

The new interface would look something like:

public interface ITagsProvider : IDependency {
    IEnumerable<string> GetTags();
}

In the OutputCacheFilter we would then inject a IEnumerable<ITagsProvider > _tagsProviders, that we would use (syntax is approximate):

Tags = new[] { _invariantCacheKey }
    .Union(cacheItemTags.Distinct())
    .Union(._tagsProviders.SelectMany(tp => tp.GetTags()).Distinct())
    .ToArray(), 

Each feature where we would implement one of these would then be able to cause its own cache evictions through its own tags.

@sebastienros
Copy link
Member

What about the other way around, a service in the output cache that allows to add custom tags to the current request. This way modules won't have to store what has changed until the output cache calls them.

@sebastienros sebastienros modified the milestones: 1.10.x, dev Dec 22, 2022
@MatteoPiovanelli-Laser
Copy link
Contributor Author

MatteoPiovanelli-Laser commented Dec 23, 2022

If I understand what you are saying, you mean something that works like the IDisplayedContentItemHandler, but rather than being invoked only on the BuildDisplay (because it's a ContentHandler), it would be possible to invoke it at any point in the code.

public interface ITagAdderService : IDependency {
    void AddTags(params string[] tags);
    IEnumerable<string> GetTags();
}

Anywhere in code:

[...]
_tagAdderService("foo", "bar");
[...]

In the OutputCacheFilter we would then inject a ITagAdderService _tagAdderService, that we would use like:

Tags = new[] { _invariantCacheKey }
    .Union(cacheItemTags.Distinct())
    .Union(_tagAdderService.Select(tp => tp.GetTags()).Distinct())
    .ToArray(),

Is that correct?

@sebastienros
Copy link
Member

Exactly.

@sebastienros
Copy link
Member

Look around orchard core, we might already be doing that.

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

No branches or pull requests

2 participants