-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Removes IDisplayedContentItemHandler in favour of ICacheTagProvider (#7792) #7793
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,6 @@ | |
| using Orchard.OutputCache.Models; | ||
| using Orchard.OutputCache.Services; | ||
| using Orchard.Services; | ||
| using Orchard.Themes; | ||
| using Orchard.UI.Admin; | ||
| using Orchard.Utility.Extensions; | ||
|
|
||
|
|
@@ -33,14 +32,12 @@ public class OutputCacheFilter : FilterProvider, IActionFilter, IResultFilter, I | |
| // Dependencies. | ||
| private readonly ICacheManager _cacheManager; | ||
| private readonly IOutputCacheStorageProvider _cacheStorageProvider; | ||
| private readonly ITagCache _tagCache; | ||
| private readonly IDisplayedContentItemHandler _displayedContentItemHandler; | ||
| private readonly IWorkContextAccessor _workContextAccessor; | ||
| private readonly IThemeManager _themeManager; | ||
| private readonly IClock _clock; | ||
| private readonly ICacheService _cacheService; | ||
| private readonly ISignals _signals; | ||
| private readonly ShellSettings _shellSettings; | ||
| private readonly IEnumerable<ICacheTagProvider> _cacheTagProviders; | ||
| private readonly ICachingEventHandler _cachingEvents; | ||
| private bool _isDisposed = false; | ||
|
|
||
|
|
@@ -49,26 +46,22 @@ public class OutputCacheFilter : FilterProvider, IActionFilter, IResultFilter, I | |
| public OutputCacheFilter( | ||
| ICacheManager cacheManager, | ||
| IOutputCacheStorageProvider cacheStorageProvider, | ||
| ITagCache tagCache, | ||
| IDisplayedContentItemHandler displayedContentItemHandler, | ||
| IWorkContextAccessor workContextAccessor, | ||
| IThemeManager themeManager, | ||
| IClock clock, | ||
| ICacheService cacheService, | ||
| ISignals signals, | ||
| ShellSettings shellSettings, | ||
| IEnumerable<ICacheTagProvider> cacheTagProviders, | ||
| ICachingEventHandler cachingEvents) { | ||
|
|
||
| _cacheManager = cacheManager; | ||
| _cacheStorageProvider = cacheStorageProvider; | ||
| _tagCache = tagCache; | ||
| _displayedContentItemHandler = displayedContentItemHandler; | ||
| _workContextAccessor = workContextAccessor; | ||
| _themeManager = themeManager; | ||
| _clock = clock; | ||
| _cacheService = cacheService; | ||
| _signals = signals; | ||
| _shellSettings = shellSettings; | ||
| _cacheTagProviders = cacheTagProviders; | ||
| _cachingEvents = cachingEvents; | ||
|
|
||
| Logger = NullLogger.Instance; | ||
|
|
@@ -206,8 +199,17 @@ public void OnResultExecuted(ResultExecutedContext filterContext) { | |
| var cacheDuration = _cacheRouteConfig != null && _cacheRouteConfig.Duration.HasValue ? _cacheRouteConfig.Duration.Value : CacheSettings.DefaultCacheDuration; | ||
| var cacheGraceTime = _cacheRouteConfig != null && _cacheRouteConfig.GraceTime.HasValue ? _cacheRouteConfig.GraceTime.Value : CacheSettings.DefaultCacheGraceTime; | ||
|
|
||
| // Include each content item ID as tags for the cache entry. | ||
| var contentItemIds = _displayedContentItemHandler.GetDisplayed().Select(x => x.ToString(CultureInfo.InvariantCulture)).ToArray(); | ||
| // Get the tags for this cache item from. | ||
| var cacheItemTags = new List<string>(); | ||
|
|
||
| foreach (var cacheTagProvider in _cacheTagProviders) { | ||
| try { | ||
| cacheItemTags.AddRange(cacheTagProvider.GetTags()); | ||
| } | ||
| catch (Exception ex) { | ||
| Logger.Warning(ex, "Cache tags from provider {0} will not be added to the cached item ({1}) because the provider threw an exception when asked to provide tags.", cacheTagProvider.GetType().FullName, _cacheKey); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An individual provider failing should not prevent the request from succeeding. Log warn and continue. |
||
| } | ||
| } | ||
|
|
||
| // Capture the response output using a custom filter stream. | ||
| var response = filterContext.HttpContext.Response; | ||
|
|
@@ -248,7 +250,7 @@ public void OnResultExecuted(ResultExecutedContext filterContext) { | |
| Url = filterContext.HttpContext.Request.Url.AbsolutePath, | ||
| Tenant = scope.Resolve<ShellSettings>().Name, | ||
| StatusCode = response.StatusCode, | ||
| Tags = new[] { _invariantCacheKey }.Union(contentItemIds).ToArray(), | ||
| Tags = new[] { _invariantCacheKey }.Union(cacheItemTags.Distinct()).ToArray(), | ||
| ETag = etag | ||
| }; | ||
|
|
||
|
|
||
13 changes: 5 additions & 8 deletions
13
...e/Handlers/DisplayedContentItemHandler.cs → ...dlers/DisplayedContentCacheTagProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,23 @@ | ||
| using System.Collections.Generic; | ||
| using System.Collections.ObjectModel; | ||
| using System.Globalization; | ||
| using System.Linq; | ||
| using Orchard.OutputCache.Services; | ||
| using Orchard.ContentManagement.Handlers; | ||
|
|
||
| namespace Orchard.OutputCache.Handlers { | ||
| /// <summary> | ||
| /// Saves references to content items which have been displayed during a request | ||
| /// Creates tags for content items which have been displayed during a request | ||
| /// </summary> | ||
| public class DisplayedContentItemHandler : ContentHandler, IDisplayedContentItemHandler { | ||
| public class DisplayedContentCacheTagProvider : ContentHandler, ICacheTagProvider { | ||
| private readonly Collection<int> _itemIds = new Collection<int>(); | ||
|
|
||
| protected override void BuildDisplayShape(BuildDisplayContext context) { | ||
| _itemIds.Add(context.Content.Id); | ||
| } | ||
|
|
||
| public bool IsDisplayed(int id) { | ||
| return _itemIds.Contains(id); | ||
| } | ||
|
|
||
| public IEnumerable<int> GetDisplayed() { | ||
| return _itemIds.Distinct(); | ||
| public IEnumerable<string> GetTags() { | ||
| return _itemIds.Distinct().Select(id => id.ToString(CultureInfo.InvariantCulture)); | ||
| } | ||
| } | ||
| } |
4 changes: 0 additions & 4 deletions
4
src/Orchard.Web/Modules/Orchard.OutputCache/ICachingEventHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/Orchard.Web/Modules/Orchard.OutputCache/Services/ICacheTagProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Orchard.OutputCache.Services { | ||
| public interface ICacheTagProvider : IDependency { | ||
| IEnumerable<string> GetTags(); | ||
| } | ||
| } |
9 changes: 0 additions & 9 deletions
9
src/Orchard.Web/Modules/Orchard.OutputCache/Services/IDisplayedContentItemHandler.cs
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ITagCacheandIThemeManagerwere already unused before this change, I just removed them to help tidy up.