From fcd7e9517d811448b4a8873ebbebedceddb23ae8 Mon Sep 17 00:00:00 2001 From: Stephan Date: Tue, 27 May 2014 12:16:41 +0200 Subject: [PATCH] U4-4931 - fixing & refactoring Conflicts: src/Umbraco.Core/Cache/DictionaryCacheProviderBase.cs src/Umbraco.Core/Cache/DictionaryCacheWrapper.cs src/Umbraco.Core/Cache/DictionaryItemWrapper.cs src/Umbraco.Core/Cache/HttpRequestCacheProvider.cs src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs --- .../Cache/DictionaryCacheProviderBase.cs | 380 ++++++++---------- .../Cache/DictionaryCacheWrapper.cs | 45 --- .../Cache/DictionaryItemWrapper.cs | 14 - .../Cache/HttpRequestCacheProvider.cs | 55 ++- .../Cache/HttpRuntimeCacheProvider.cs | 143 +------ .../Cache/ObjectCacheRuntimeCacheProvider.cs | 40 +- src/Umbraco.Core/Umbraco.Core.csproj | 2 - 7 files changed, 238 insertions(+), 441 deletions(-) delete mode 100644 src/Umbraco.Core/Cache/DictionaryCacheWrapper.cs delete mode 100644 src/Umbraco.Core/Cache/DictionaryItemWrapper.cs diff --git a/src/Umbraco.Core/Cache/DictionaryCacheProviderBase.cs b/src/Umbraco.Core/Cache/DictionaryCacheProviderBase.cs index 6fdcc28895..52144ed17c 100644 --- a/src/Umbraco.Core/Cache/DictionaryCacheProviderBase.cs +++ b/src/Umbraco.Core/Cache/DictionaryCacheProviderBase.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; @@ -8,232 +9,169 @@ namespace Umbraco.Core.Cache { internal abstract class DictionaryCacheProviderBase : ICacheProvider { - protected readonly ReaderWriterLockSlim Locker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); - protected abstract DictionaryCacheWrapper DictionaryCache { get; } - - /// - /// Clears everything in umbraco's runtime cache - /// - /// - /// Does not clear other stuff the user has put in httpruntime.cache! - /// - public virtual void ClearAllCache() - { - using (new WriteLock(Locker)) - { - var keysToRemove = DictionaryCache.Cast() - .Select(item => new DictionaryItemWrapper(item)) - .Where(c => c.Key is string && ((string)c.Key).StartsWith(CacheItemPrefix) && DictionaryCache[c.Key.ToString()] != null) - .Select(c => c.Key) - .ToList(); - - foreach (var k in keysToRemove) - { - DictionaryCache.Remove(k); - } - } - } - - /// - /// Clears the item in umbraco's runtime cache with the given key - /// - /// Key - public virtual void ClearCacheItem(string key) - { - using (new WriteLock(Locker)) - { - var cacheKey = GetCacheKey(key); - if (DictionaryCache[cacheKey] == null) return; - DictionaryCache.Remove(cacheKey); - } - } - - /// - /// Clears all objects in the System.Web.Cache with the System.Type name as the - /// input parameter. (using [object].GetType()) - /// - /// The name of the System.Type which should be cleared from cache ex "System.Xml.XmlDocument" - public virtual void ClearCacheObjectTypes(string typeName) - { - using (new WriteLock(Locker)) - { - var keysToRemove = DictionaryCache - .Cast() - .Select(item => new DictionaryItemWrapper(item)) - .Where(c => - { - var k = c.Key.ToString(); - var v = DictionaryCache[k]; - return v != null && v.GetType().ToString().InvariantEquals(typeName); - }) - .Select(c => c.Key) - .ToList(); - - foreach (var k in keysToRemove) - DictionaryCache.Remove(k); - } - } - - public virtual void ClearCacheObjectTypes() - { - using (new WriteLock(Locker)) - { - var typeOfT = typeof(T); - var keysToRemove = DictionaryCache - .Cast() - .Select(item => new DictionaryItemWrapper(item)) - .Where(c => - { - var k = c.Key.ToString(); - var v = DictionaryCache[k]; - return v != null && v.GetType() == typeOfT; - }) - .Select(c => c.Key) - .ToList(); - - foreach (var k in keysToRemove) - DictionaryCache.Remove(k); - } - } - - public virtual void ClearCacheObjectTypes(Func predicate) - { - using (new WriteLock(Locker)) - { - var typeOfT = typeof(T); - var keysToRemove = DictionaryCache - .Cast() - .Select(item => new DictionaryItemWrapper(item)) - .Where(c => - { - var k = c.Key.ToString(); - var v = DictionaryCache[k]; - return v != null && v.GetType() == typeOfT && predicate(k, (T)v); - }) - .Select(c => c.Key) - .ToList(); - - foreach (var k in keysToRemove) - DictionaryCache.Remove(k); - } - } - - /// - /// Clears all cache items that starts with the key passed. - /// - /// The start of the key - public virtual void ClearCacheByKeySearch(string keyStartsWith) - { - using (new WriteLock(Locker)) - { - var keysToRemove = DictionaryCache.Cast() - .Select(item => new DictionaryItemWrapper(item)) - .Where( - c => - c.Key is string && - ((string) c.Key).InvariantStartsWith(string.Format("{0}-{1}", CacheItemPrefix, keyStartsWith))) - .Select(c => c.Key) - .ToList(); - - foreach (var k in keysToRemove) - { - DictionaryCache.Remove(k); - } - } - } - - /// - /// Clears all cache items that have a key that matches the regular expression - /// - /// - public virtual void ClearCacheByKeyExpression(string regexString) - { - using (new WriteLock(Locker)) - { - var keysToRemove = new List(); - foreach (var item in DictionaryCache) - { - var c = new DictionaryItemWrapper(item); - var s = c.Key as string; - if (s != null) - { - var withoutPrefix = s.TrimStart(string.Format("{0}-", CacheItemPrefix)); - if (Regex.IsMatch(withoutPrefix, regexString)) - { - keysToRemove.Add(c.Key); - } - } - } - - foreach (var k in keysToRemove) - { - DictionaryCache.Remove(k); - } - } - } - - public virtual IEnumerable GetCacheItemsByKeySearch(string keyStartsWith) - { - using (new ReadLock(Locker)) - { - return (from object item in DictionaryCache - select new DictionaryItemWrapper(item) - into c - where - c.Key is string && - ((string) c.Key).InvariantStartsWith(string.Format("{0}-{1}", CacheItemPrefix, keyStartsWith)) - select c.Value).ToList(); - } - } - - public virtual IEnumerable GetCacheItemsByKeyExpression(string regexString) - { - using (new ReadLock(Locker)) - { - var found = new List(); - foreach (var item in DictionaryCache) - { - var c = new DictionaryItemWrapper(item); - var s = c.Key as string; - if (s != null) - { - var withoutPrefix = s.TrimStart(string.Format("{0}-", CacheItemPrefix)); - if (Regex.IsMatch(withoutPrefix, regexString)) - { - found.Add(c.Value); - } - } - } - - return found; - } - } - - /// - /// Returns a cache item by key, does not update the cache if it isn't there. - /// - /// - /// - public virtual object GetCacheItem(string cacheKey) - { - using (new ReadLock(Locker)) - { - var result = DictionaryCache.Get(GetCacheKey(cacheKey)); - return result; - } - } - - public abstract object GetCacheItem(string cacheKey, Func getCacheItem); - - /// - /// We prefix all cache keys with this so that we know which ones this class has created when - /// using the HttpRuntime cache so that when we clear it we don't clear other entries we didn't create. - /// + // prefix cache keys so we know which one are ours protected const string CacheItemPrefix = "umbrtmche"; + protected readonly ReaderWriterLockSlim Locker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); + + // manupulate the underlying cache entries + // these *must* be called from within the appropriate locks + // and use the full prefixed cache keys + protected abstract IEnumerable GetDictionaryEntries(); + protected abstract void RemoveEntry(string key); + protected abstract object GetEntry(string key); + protected string GetCacheKey(string key) { return string.Format("{0}-{1}", CacheItemPrefix, key); } + + #region Clear + + public virtual void ClearAllCache() + { + using (new WriteLock(Locker)) + { + foreach (var entry in GetDictionaryEntries() + .ToArray()) + RemoveEntry((string) entry.Key); + } + } + + public virtual void ClearCacheItem(string key) + { + using (new WriteLock(Locker)) + { + var cacheKey = GetCacheKey(key); + RemoveEntry(cacheKey); + } + } + + public virtual void ClearCacheObjectTypes(string typeName) + { + using (new WriteLock(Locker)) + { + foreach (var entry in GetDictionaryEntries() + .Where(x => + { + // entry.Value is Lazy and not null, its value may be null + // remove null values as well, does not hurt + var value = ((Lazy) x.Value).Value; + return value == null || value.GetType().ToString().InvariantEquals(typeName); + }) + .ToArray()) + RemoveEntry((string) entry.Key); + } + } + + public virtual void ClearCacheObjectTypes() + { + var typeOfT = typeof(T); + using (new WriteLock(Locker)) + { + foreach (var entry in GetDictionaryEntries() + .Where(x => + { + // entry.Value is Lazy and not null, its value may be null + // remove null values as well, does not hurt + // compare on exact type, don't use "is" + var value = ((Lazy)x.Value).Value; + return value == null || value.GetType() == typeOfT; + }) + .ToArray()) + RemoveEntry((string) entry.Key); + } + } + + public virtual void ClearCacheObjectTypes(Func predicate) + { + var typeOfT = typeof(T); + var plen = CacheItemPrefix.Length + 1; + using (new WriteLock(Locker)) + { + foreach (var entry in GetDictionaryEntries() + .Where(x => + { + // entry.Value is Lazy and not null, its value may be null + // remove null values as well, does not hurt + // compare on exact type, don't use "is" + var value = ((Lazy)x.Value).Value; + if (value == null) return true; + return value.GetType() == typeOfT + // run predicate on the 'public key' part only, ie without prefix + && predicate(((string)x.Key).Substring(plen), (T)value); + })) + RemoveEntry((string) entry.Key); + } + } + + public virtual void ClearCacheByKeySearch(string keyStartsWith) + { + var plen = CacheItemPrefix.Length + 1; + using (new WriteLock(Locker)) + { + foreach (var entry in GetDictionaryEntries() + .Where(x => ((string)x.Key).Substring(plen).InvariantStartsWith(keyStartsWith)) + .ToArray()) + RemoveEntry((string) entry.Key); + } + } + + public virtual void ClearCacheByKeyExpression(string regexString) + { + var plen = CacheItemPrefix.Length + 1; + using (new WriteLock(Locker)) + { + foreach (var entry in GetDictionaryEntries() + .Where(x => Regex.IsMatch(((string)x.Key).Substring(plen), regexString)) + .ToArray()) + RemoveEntry((string) entry.Key); + } + } + + #endregion + + #region Get + + public virtual IEnumerable GetCacheItemsByKeySearch(string keyStartsWith) + { + var plen = CacheItemPrefix.Length + 1; + using (new ReadLock(Locker)) + { + return GetDictionaryEntries() + .Where(x => ((string)x.Key).Substring(plen).InvariantStartsWith(keyStartsWith)) + .Select(x => ((Lazy)x.Value).Value) + .Where(x => x != null) // backward compat, don't store null values in the cache + .ToList(); + } + } + + public virtual IEnumerable GetCacheItemsByKeyExpression(string regexString) + { + const string prefix = CacheItemPrefix + "-"; + var plen = prefix.Length; + using (new ReadLock(Locker)) + { + return GetDictionaryEntries() + .Where(x => Regex.IsMatch(((string)x.Key).Substring(plen), regexString)) + .Select(x => ((Lazy)x.Value).Value) + .Where(x => x != null) // backward compat, don't store null values in the cache + .ToList(); + } + } + + public virtual object GetCacheItem(string cacheKey) + { + cacheKey = GetCacheKey(cacheKey); + using (new ReadLock(Locker)) + { + var result = GetEntry(cacheKey) as Lazy; // null if key not found + return result == null ? null : result.Value; + } + } + + public abstract object GetCacheItem(string cacheKey, Func getCacheItem); + + #endregion } } \ No newline at end of file diff --git a/src/Umbraco.Core/Cache/DictionaryCacheWrapper.cs b/src/Umbraco.Core/Cache/DictionaryCacheWrapper.cs deleted file mode 100644 index 840a1c01b3..0000000000 --- a/src/Umbraco.Core/Cache/DictionaryCacheWrapper.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections; - -namespace Umbraco.Core.Cache -{ - internal class DictionaryCacheWrapper : IEnumerable - { - private readonly IEnumerable _inner; - private readonly Func _get; - private readonly Action _remove; - - public DictionaryCacheWrapper( - IEnumerable inner, - Func get, - Action remove) - { - _inner = inner; - _get = get; - _remove = remove; - } - - public object this[object key] - { - get - { - return Get(key); - } - } - - public object Get(object key) - { - return _get(key); - } - - public void Remove(object key) - { - _remove(key); - } - - public IEnumerator GetEnumerator() - { - return _inner.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Cache/DictionaryItemWrapper.cs b/src/Umbraco.Core/Cache/DictionaryItemWrapper.cs deleted file mode 100644 index 724f5f43b0..0000000000 --- a/src/Umbraco.Core/Cache/DictionaryItemWrapper.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Umbraco.Core.Cache -{ - internal class DictionaryItemWrapper - { - public DictionaryItemWrapper(dynamic item) - { - Key = item.Key; - Value = item.Value; - } - - public object Key { get; private set; } - public object Value { get; private set; } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Cache/HttpRequestCacheProvider.cs b/src/Umbraco.Core/Cache/HttpRequestCacheProvider.cs index b71317b31d..989fd3a69d 100644 --- a/src/Umbraco.Core/Cache/HttpRequestCacheProvider.cs +++ b/src/Umbraco.Core/Cache/HttpRequestCacheProvider.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Text.RegularExpressions; using System.Web; namespace Umbraco.Core.Cache @@ -16,7 +15,9 @@ namespace Umbraco.Core.Cache public HttpRequestCacheProvider(HttpContext context) { - _context = () => new HttpContextWrapper(context); + // create wrapper only once! + var wrapper = new HttpContextWrapper(context); + _context = () => wrapper; } public HttpRequestCacheProvider(Func context) @@ -24,24 +25,50 @@ namespace Umbraco.Core.Cache _context = context; } - protected override DictionaryCacheWrapper DictionaryCache + protected override IEnumerable GetDictionaryEntries() { - get - { - var ctx = _context(); - return new DictionaryCacheWrapper( - ctx.Items, - o => ctx.Items[o], - o => ctx.Items.Remove(o)); - } + const string prefix = CacheItemPrefix + "-"; + return _context().Items.Cast() + .Where(x => x.Key is string && ((string)x.Key).StartsWith(prefix)); } + protected override void RemoveEntry(string key) + { + _context().Items.Remove(key); + } + + protected override object GetEntry(string key) + { + return _context().Items[key]; + } + + #region Get + public override object GetCacheItem(string cacheKey, Func getCacheItem) { - var ctx = _context(); - var ck = GetCacheKey(cacheKey); - return ctx.Items[ck] ?? (ctx.Items[ck] = getCacheItem()); + cacheKey = GetCacheKey(cacheKey); + + Lazy result; + + using (var lck = new UpgradeableReadLock(Locker)) + { + result = _context().Items[cacheKey] as Lazy; // null if key not found + if (result == null || (result.IsValueCreated && result.Value == null)) + { + lck.UpgradeToWriteLock(); + + result = new Lazy(getCacheItem); + _context().Items[cacheKey] = result; + } + } + + return result.Value; } + + #endregion + + #region Insert + #endregion } } \ No newline at end of file diff --git a/src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs b/src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs index c4f14fdeec..70e18fada4 100644 --- a/src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs +++ b/src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs @@ -2,11 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Text.RegularExpressions; -using System.Threading; -using System.Web; using System.Web.Caching; -using Umbraco.Core.Logging; using CacheItemPriority = System.Web.Caching.CacheItemPriority; namespace Umbraco.Core.Cache @@ -17,148 +13,31 @@ namespace Umbraco.Core.Cache internal class HttpRuntimeCacheProvider : DictionaryCacheProviderBase, IRuntimeCacheProvider { private readonly System.Web.Caching.Cache _cache; - private readonly DictionaryCacheWrapper _wrapper; - + public HttpRuntimeCacheProvider(System.Web.Caching.Cache cache) { _cache = cache; - _wrapper = new DictionaryCacheWrapper(_cache, s => _cache.Get(s.ToString()), o => _cache.Remove(o.ToString())); } - protected override DictionaryCacheWrapper DictionaryCache - { - get { return _wrapper; } - } - - public override void ClearAllCache() - { - using (new WriteLock(Locker)) - { - foreach (var entry in GetDictionaryEntries()) - _cache.Remove((string)entry.Key); - } - } - - public override void ClearCacheItem(string key) - { - using (new WriteLock(Locker)) - { - var cacheKey = GetCacheKey(key); - _cache.Remove(cacheKey); - } - } - - public override void ClearCacheObjectTypes(string typeName) - { - using (new WriteLock(Locker)) - { - foreach (var entry in GetDictionaryEntries() - .Where(x => - { - // entry.Value is Lazy and not null, its value may be null - var value = ((Lazy) x.Value).Value; - return value == null || value.GetType().ToString().InvariantEquals(typeName); // remove null values as well - })) - _cache.Remove((string)entry.Key); - } - } - - public override void ClearCacheObjectTypes() - { - // note: compare on exact type, don't use "is" - - var typeOfT = typeof(T); - using (new WriteLock(Locker)) - { - foreach (var entry in GetDictionaryEntries() - .Where(x => - { - // entry.Value is Lazy and not null, its value may be null - var value = ((Lazy)x.Value).Value; - return value == null || value.GetType() == typeOfT; // remove null values as well - })) - _cache.Remove((string)entry.Key); - } - } - - public override void ClearCacheObjectTypes(Func predicate) - { - // note: compare on exact type, don't use "is" - - var typeOfT = typeof(T); - var plen = CacheItemPrefix.Length + 1; - using (new WriteLock(Locker)) - { - foreach (var entry in GetDictionaryEntries() - .Where(x => - { - // entry.Value is Lazy and not null, its value may be null - var value = ((Lazy)x.Value).Value; - if (value == null) return true; // remove null values as well - return value.GetType() == typeOfT - // run predicate on the 'public key' part only, ie without prefix - && predicate(((string) x.Key).Substring(plen), (T) value); - })) - _cache.Remove((string)entry.Key); - } - } - - public override void ClearCacheByKeySearch(string keyStartsWith) - { - var plen = CacheItemPrefix.Length + 1; - using (new WriteLock(Locker)) - { - foreach (var entry in GetDictionaryEntries() - .Where(x => ((string)x.Key).Substring(plen).InvariantStartsWith(keyStartsWith))) - _cache.Remove((string)entry.Key); - } - } - - public override void ClearCacheByKeyExpression(string regexString) - { - var plen = CacheItemPrefix.Length + 1; - using (new WriteLock(Locker)) - { - foreach (var entry in GetDictionaryEntries() - .Where(x => Regex.IsMatch(((string)x.Key).Substring(plen), regexString))) - _cache.Remove((string)entry.Key); - } - } - - private IEnumerable GetDictionaryEntries() + protected override IEnumerable GetDictionaryEntries() { const string prefix = CacheItemPrefix + "-"; return _cache.Cast() .Where(x => x.Key is string && ((string) x.Key).StartsWith(prefix)); } - public override IEnumerable GetCacheItemsByKeySearch(string keyStartsWith) + protected override void RemoveEntry(string key) { - var plen = CacheItemPrefix.Length + 1; - using (new ReadLock(Locker)) - { - return GetDictionaryEntries() - .Where(x => ((string) x.Key).Substring(plen).InvariantStartsWith(keyStartsWith)) - .Select(x => ((Lazy)x.Value).Value) - .Where(x => x != null) // backward compat, don't store null values in the cache - .ToList(); - } + _cache.Remove(key); } - public override IEnumerable GetCacheItemsByKeyExpression(string regexString) + protected override object GetEntry(string key) { - const string prefix = CacheItemPrefix + "-"; - var plen = prefix.Length; - using (new ReadLock(Locker)) - { - return GetDictionaryEntries() - .Where(x => Regex.IsMatch(((string) x.Key).Substring(plen), regexString)) - .Select(x => ((Lazy)x.Value).Value) - .Where(x => x != null) // backward compat, don't store null values in the cache - .ToList(); - } + return _cache.Get(key); } + #region Get + /// /// Gets (and adds if necessary) an item from the cache with all of the default parameters /// @@ -230,6 +109,10 @@ namespace Umbraco.Core.Cache return GetCacheItem(cacheKey, getCacheItem, timeout, isSliding, priority, removedCallback, dependency); } + #endregion + + #region Insert + /// /// This overload is here for legacy purposes /// @@ -266,5 +149,7 @@ namespace Umbraco.Core.Cache } InsertCacheItem(cacheKey, getCacheItem, timeout, isSliding, priority, removedCallback, dependency); } + + #endregion } } \ No newline at end of file diff --git a/src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs b/src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs index 1153fe54a3..945a4588d2 100644 --- a/src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs +++ b/src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs @@ -24,6 +24,8 @@ namespace Umbraco.Core.Cache MemoryCache = new MemoryCache("in-memory"); } + #region Clear + public virtual void ClearAllCache() { using (new WriteLock(_locker)) @@ -50,8 +52,9 @@ namespace Umbraco.Core.Cache .Where(x => { // x.Value is Lazy and not null, its value may be null + // remove null values as well, does not hurt var value = ((Lazy) x.Value).Value; - return value == null || value.GetType().ToString().InvariantEquals(typeName); // remove null values as well + return value == null || value.GetType().ToString().InvariantEquals(typeName); }) .Select(x => x.Key) .ToArray()) // ToArray required to remove @@ -68,8 +71,9 @@ namespace Umbraco.Core.Cache .Where(x => { // x.Value is Lazy and not null, its value may be null - var value = ((Lazy) x.Value).Value; - return value == null || value.GetType() == typeOfT; // remove null values as well + // remove null values as well, does not hurt + var value = ((Lazy)x.Value).Value; + return value == null || value.GetType() == typeOfT; }) .Select(x => x.Key) .ToArray()) // ToArray required to remove @@ -86,8 +90,9 @@ namespace Umbraco.Core.Cache .Where(x => { // x.Value is Lazy and not null, its value may be null - var value = ((Lazy) x.Value).Value; - if (value == null) return true; // remove null values as well + // remove null values as well, does not hurt + var value = ((Lazy)x.Value).Value; + if (value == null) return true; return value.GetType() == typeOfT && predicate(x.Key, (T) value); }) @@ -121,7 +126,11 @@ namespace Umbraco.Core.Cache } } - public virtual IEnumerable GetCacheItemsByKeySearch(string keyStartsWith) + #endregion + + #region Get + + public IEnumerable GetCacheItemsByKeySearch(string keyStartsWith) { using (new ReadLock(_locker)) { @@ -145,7 +154,7 @@ namespace Umbraco.Core.Cache } } - public virtual object GetCacheItem(string cacheKey) + public object GetCacheItem(string cacheKey) { using (new ReadLock(_locker)) { @@ -154,19 +163,12 @@ namespace Umbraco.Core.Cache } } - public virtual object GetCacheItem(string cacheKey, Func getCacheItem) + public object GetCacheItem(string cacheKey, Func getCacheItem) { return GetCacheItem(cacheKey, getCacheItem, null); } - public object GetCacheItem( - string cacheKey, - Func getCacheItem, - TimeSpan? timeout, - bool isSliding = false, - CacheItemPriority priority = CacheItemPriority.Normal, - CacheItemRemovedCallback removedCallback = null, - string[] dependentFiles = null) + public object GetCacheItem(string cacheKey, Func getCacheItem, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal,CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) { // see notes in HttpRuntimeCacheProvider @@ -188,6 +190,10 @@ namespace Umbraco.Core.Cache return result.Value; } + #endregion + + #region Insert + public void InsertCacheItem(string cacheKey, Func getCacheItem, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) { // NOTE - here also we must insert a Lazy but we can evaluate it right now @@ -201,6 +207,8 @@ namespace Umbraco.Core.Cache MemoryCache.Set(cacheKey, result, policy); } + #endregion + private static CacheItemPolicy GetPolicy(TimeSpan? timeout = null, bool isSliding = false, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) { var absolute = isSliding ? ObjectCache.InfiniteAbsoluteExpiration : (timeout == null ? ObjectCache.InfiniteAbsoluteExpiration : DateTime.Now.Add(timeout.Value)); diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 17709c7283..f58cf0800c 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -146,8 +146,6 @@ - -