using System;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Caching;
using Umbraco.Core.Logging;
using CacheItemPriority = System.Web.Caching.CacheItemPriority;
namespace Umbraco.Core.Cache
{
///
/// A CacheProvider that wraps the logic of the HttpRuntime.Cache
///
internal class HttpRuntimeCacheProvider : DictionaryCacheProdiverBase, 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
/// Clears all objects in the System.Web.Cache with the System.Type specified that satisfy the predicate
///
public override void ClearCacheObjectTypes(Func predicate)
{
try
{
lock (Locker)
{
foreach (DictionaryEntry c in _cache)
{
var key = c.Key.ToString();
if (_cache[key] != null
&& _cache[key] is T
&& predicate(key, (T)_cache[key]))
{
_cache.Remove(c.Key.ToString());
}
}
}
}
catch (Exception e)
{
LogHelper.Error("Cache clearing error", e);
}
}
///
{
get { return _wrapper; }
}
///
/// Gets (and adds if necessary) an item from the cache with all of the default parameters
///
///
///
///
public override object GetCacheItem(string cacheKey, Func