Core.Cache - add new method to remove items from cache

This commit is contained in:
Stephan
2013-09-18 10:05:44 +02:00
parent 95df28bf64
commit 761354dbf5
5 changed files with 49 additions and 32 deletions

View File

@@ -27,50 +27,27 @@ namespace Umbraco.Core.Cache
public override void ClearCacheObjectTypes(string typeName)
{
foreach (var key in _staticCache.Keys)
{
if (_staticCache[key] != null
&& _staticCache[key].GetType().ToString().InvariantEquals(typeName))
{
object val;
_staticCache.TryRemove(key, out val);
}
}
_staticCache.RemoveAll(kvp => kvp.Value.GetType().ToString().InvariantEquals(typeName));
}
public override void ClearCacheObjectTypes<T>()
{
foreach (var key in _staticCache.Keys)
{
if (_staticCache[key] != null
&& _staticCache[key].GetType() == typeof(T))
{
object val;
_staticCache.TryRemove(key, out val);
}
}
_staticCache.RemoveAll(kvp => kvp.Value is T);
}
public override void ClearCacheObjectTypes<T>(Func<string, T, bool> predicate)
{
_staticCache.RemoveAll(kvp => kvp.Value is T && predicate(kvp.Key, (T)kvp.Value));
}
public override void ClearCacheByKeySearch(string keyStartsWith)
{
foreach (var key in _staticCache.Keys)
{
if (key.InvariantStartsWith(keyStartsWith))
{
ClearCacheItem(key);
}
}
_staticCache.RemoveAll(kvp => kvp.Key.InvariantStartsWith(keyStartsWith));
}
public override void ClearCacheByKeyExpression(string regexString)
{
foreach (var key in _staticCache.Keys)
{
if (Regex.IsMatch(key, regexString))
{
ClearCacheItem(key);
}
}
_staticCache.RemoveAll(kvp => Regex.IsMatch(kvp.Key, regexString));
}
public override IEnumerable<T> GetCacheItemsByKeySearch<T>(string keyStartsWith)