mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Prevent cache of pages with notifications
This commit is contained in:
@@ -40,7 +40,6 @@ namespace Orchard.OutputCache.Filters {
|
||||
private readonly ISignals _signals;
|
||||
private readonly ShellSettings _shellSettings;
|
||||
private readonly ICacheControlStrategy _cacheControlStrategy;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
TextWriter _originalWriter;
|
||||
StringWriter _cachingWriter;
|
||||
@@ -59,8 +58,7 @@ namespace Orchard.OutputCache.Filters {
|
||||
ICacheService cacheService,
|
||||
ISignals signals,
|
||||
ShellSettings shellSettings,
|
||||
ICacheControlStrategy cacheControlStrategy,
|
||||
INotifier notifier) {
|
||||
ICacheControlStrategy cacheControlStrategy) {
|
||||
|
||||
_cacheManager = cacheManager;
|
||||
_cacheStorageProvider = cacheStorageProvider;
|
||||
@@ -73,7 +71,6 @@ namespace Orchard.OutputCache.Filters {
|
||||
_signals = signals;
|
||||
_shellSettings = shellSettings;
|
||||
_cacheControlStrategy = cacheControlStrategy;
|
||||
_notifier = notifier;
|
||||
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
@@ -347,7 +344,9 @@ namespace Orchard.OutputCache.Filters {
|
||||
}
|
||||
|
||||
// don't cache the result if there were some notifications
|
||||
if (_notifier.List().Any()) {
|
||||
var hasNotifications = !String.IsNullOrEmpty(Convert.ToString(filterContext.Controller.TempData["messages"]));
|
||||
if (hasNotifications) {
|
||||
Logger.Debug("Not caching: notifications present");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -375,10 +374,8 @@ namespace Orchard.OutputCache.Filters {
|
||||
|
||||
Logger.Debug("Cache item added: " + _cacheItem.CacheKey);
|
||||
|
||||
// remove only the current version of the page
|
||||
_cacheService.RemoveByTag(_cacheKey);
|
||||
|
||||
// add data to cache
|
||||
// update the cached data
|
||||
_cacheStorageProvider.Remove(_cacheKey);
|
||||
_cacheStorageProvider.Set(_cacheKey, _cacheItem);
|
||||
|
||||
// add to the tags index
|
||||
|
||||
@@ -40,6 +40,9 @@ namespace Orchard.OutputCache.Services {
|
||||
foreach(var key in _tagCache.GetTaggedItems(tag)) {
|
||||
_cacheStorageProvider.Remove(key);
|
||||
}
|
||||
|
||||
// we no longer need the tag entry as the items have been removed
|
||||
_tagCache.RemoveTag(tag);
|
||||
}
|
||||
|
||||
public IEnumerable<CacheItem> GetCacheItems() {
|
||||
|
||||
@@ -37,5 +37,10 @@ namespace Orchard.OutputCache.Services {
|
||||
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
public void RemoveTag(string tag) {
|
||||
HashSet<string> set;
|
||||
_dictionary.TryRemove(tag, out set);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,6 @@ namespace Orchard.OutputCache.Services {
|
||||
public interface ITagCache : ISingletonDependency {
|
||||
void Tag(string tag, params string[] keys);
|
||||
IEnumerable<string> GetTaggedItems(string tag);
|
||||
void RemoveTag(string tag);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user