Default Tag Cache from HttpContext (#7280)

Fixes #7240
This commit is contained in:
Hannan Azam Khan
2016-11-18 01:54:04 +05:00
committed by Sébastien Ros
parent 4584da9214
commit 7e859f2ccf

View File

@@ -2,19 +2,27 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using Orchard.OutputCache.Models;
using Orchard.Utility.Extensions;
using Orchard.Environment.Configuration;
using System.Web.Caching;
namespace Orchard.OutputCache.Services {
/// <summary>
/// Tenant wide case insensitive reverse index for <see cref="CacheItem"/> tags.
/// </summary>
public class DefaultTagCache : ITagCache {
private readonly ConcurrentDictionary<string, HashSet<string>> _dictionary;
public DefaultTagCache() {
_dictionary = new ConcurrentDictionary<string, HashSet<string>>(StringComparer.OrdinalIgnoreCase);
public DefaultTagCache(IWorkContextAccessor workContextAccessor, ShellSettings shellSettings) {
var key = shellSettings.Name + ":TagCache";
var workContext = workContextAccessor.GetContext();
_dictionary = workContext.HttpContext.Cache.Get(key) as ConcurrentDictionary<string, HashSet<string>>;
if (_dictionary == null) {
_dictionary = new ConcurrentDictionary<string, HashSet<string>>(StringComparer.OrdinalIgnoreCase);
workContext.HttpContext.Cache.Add(key, _dictionary, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
}
}
public void Tag(string tag, params string[] keys) {
@@ -26,7 +34,7 @@ namespace Orchard.OutputCache.Services {
}
}
}
public IEnumerable<string> GetTaggedItems(string tag) {
HashSet<string> set;
if (_dictionary.TryGetValue(tag, out set)) {