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

@@ -103,6 +103,33 @@ namespace Umbraco.Core.Cache
}
}
/// <summary>
/// Clears all objects in the System.Web.Cache with the System.Type specified that satisfy the predicate
/// </summary>
public override void ClearCacheObjectTypes<T>(Func<string, T, bool> 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<CacheHelper>("Cache clearing error", e);
}
}
/// <summary>
/// Clears all cache items that starts with the key passed.
/// </summary>