/// <summary> /// Formats the concatenation of the cache tag /// </summary> /// <param name="type"></param> /// <param name="identifier"></param> /// <returns></returns> public static string FormatTag(CacheTags type, dynamic identifier) { if (identifier == null) { identifier = "null"; } string id = type.ToString() + identifier.ToString(); return(id); }
/// <summary> /// Clears all the items with this tag /// </summary> /// <param name="tag"></param> public void ClearTag(CacheTags cacheTag, dynamic id) { if (id == null) { id = ""; } string tag = cacheTag.ToString() + id; var keysToRemove = new List <string>(); foreach (DictionaryEntry item in System.Web.HttpRuntime.Cache) { if (!(item.Value is ICachable)) { continue; } var key = (ICachable)item.Value; if (key.Tags.Contains(tag)) { keysToRemove.Add(item.Key.ToString()); } } // Remove each foreach (var cacheKey in keysToRemove) { try { if (System.Web.HttpRuntime.Cache[cacheKey] != null) { System.Web.HttpRuntime.Cache.Remove(cacheKey); } } catch { } } }