using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Umbraco.Core.Cache
{
///
/// Represents a cache provider that statically caches item in a concurrent dictionary.
///
public class StaticCacheProvider : ICacheProvider
{
internal readonly ConcurrentDictionary StaticCache = new ConcurrentDictionary();
public virtual void ClearAllCache()
{
StaticCache.Clear();
}
public virtual void ClearCacheItem(string key)
{
object val;
StaticCache.TryRemove(key, out val);
}
public virtual void ClearCacheObjectTypes(string typeName)
{
StaticCache.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType().ToString().InvariantEquals(typeName));
}
public virtual void ClearCacheObjectTypes()
{
var typeOfT = typeof(T);
StaticCache.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT);
}
public virtual void ClearCacheObjectTypes(Func predicate)
{
var typeOfT = typeof(T);
StaticCache.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT && predicate(kvp.Key, (T)kvp.Value));
}
public virtual void ClearCacheByKeySearch(string keyStartsWith)
{
StaticCache.RemoveAll(kvp => kvp.Key.InvariantStartsWith(keyStartsWith));
}
public virtual void ClearCacheByKeyExpression(string regexString)
{
StaticCache.RemoveAll(kvp => Regex.IsMatch(kvp.Key, regexString));
}
public virtual IEnumerable