/// <summary>Expire all cached keys linked to specified tags.</summary> /// <param name="tags"> /// A variable-length parameters list containing tag to expire linked cache /// key. /// </param> public static void ExpireTag(params string[] tags) { foreach (var tag in tags) { List <string> list; if (CacheTags.TryRemove(CachePrefix + tag, out list)) { foreach (var item in list) { Cache.Remove(item); } } } }
/// <summary>Expire all cached keys linked to specified tags.</summary> /// <param name="tags"> /// A variable-length parameters list containing tag to expire linked cache /// key. /// </param> public static void ExpireTag(params string[] tags) { foreach (var tag in tags) { List <string> list; if (CacheTags.TryRemove(CachePrefix + tag, out list)) { // never lock something related to this list elsewhere or ensure we don't create a deadlock lock (list) { foreach (var item in list) { Cache.Remove(item); } } } } }
/// <summary>Expire all cached objects && tag.</summary> public static void ExpireAll() { var tags = CacheTags.Select(x => x.Key).ToList(); // We do not use ExpireTag because type doesn't have CachePrefix foreach (var tag in tags) { List <string> list; if (CacheTags.TryRemove(tag, out list)) { // never lock something related to this list elsewhere or ensure we don't create a deadlock lock (list) { foreach (var item in list) { Cache.Remove(item); } } } } }