// remove cache vary // remove entry internal static void Remove(String key, HttpContext context) { // we don't know if it's in the internal cache or // one of the providers. If a context is given, // then we can narrow down to at most one provider. // If the context is null, then we don't know which // provider and we have to check all. HttpRuntime.CacheInternal.Remove(key); if (context == null) { // remove from all providers since we don't know which one it's in. OutputCacheProviderCollection providers = Providers; if (providers != null) { foreach (OutputCacheProvider provider in providers) { provider.Remove(key); } } } else { OutputCacheProvider provider = GetProvider(context); if (provider != null) { provider.Remove(key); } } #if DBG Debug.Trace("OutputCache", "Remove(" + key + ", context)"); #endif }
internal static void RemoveFragment(string key, string providerName) { OutputCacheProvider fragmentProvider = GetFragmentProvider(providerName); if (fragmentProvider != null) { fragmentProvider.Remove(key); } HttpRuntime.CacheInternal.Remove(key); }
void OnBuildManagerRemoveEntry(BuildManagerRemoveEntryEventArgs args) { string entry = args.EntryName; HttpContext context = args.Context; string cacheValue; lock (keysCacheLock) { if (!keysCache.TryGetValue(entry, out cacheValue)) { return; } keysCache.Remove(entry); if (context == null) { if (entriesToInvalidate == null) { entriesToInvalidate = new Dictionary <string, string> (StringComparer.Ordinal); entriesToInvalidate.Add(entry, cacheValue); return; } else if (!entriesToInvalidate.ContainsKey(entry)) { entriesToInvalidate.Add(entry, cacheValue); return; } } } OutputCacheProvider provider = FindCacheProvider(context != null ? context.ApplicationInstance : null); provider.Remove(entry); if (!String.IsNullOrEmpty(cacheValue)) { provider.Remove(cacheValue); } }
void OnRawResponseRemoved(string key, object value, CacheItemRemovedReason reason) { CachedRawResponse c = value as CachedRawResponse; CachedVaryBy varyby = c != null ? c.VaryBy : null; if (varyby == null) { return; } List <string> itemList = varyby.ItemList; OutputCacheProvider provider = FindCacheProvider(null); itemList.Remove(key); provider.Remove(key); if (itemList.Count != 0) { return; } provider.Remove(varyby.Key); }
internal static void RemoveFromProvider(string key, string providerName) { if (providerName == null) { throw new ArgumentNullException("providerName"); } OutputCacheProviderCollection providers = Providers; OutputCacheProvider provider = (providers == null) ? null : providers[providerName]; if (provider == null) { throw new ProviderException(System.Web.SR.GetString("Provider_Not_Found", new object[] { providerName })); } provider.Remove(key); }
// remove fragment internal static void RemoveFragment(String key, String providerName) { // if providerName is null, use default provider. // if providerName is not null, get it from the provider collection. // remove it from the provider and the internal cache (we don't know where it is). OutputCacheProvider provider = GetFragmentProvider(providerName); if (provider != null) { provider.Remove(key); } HttpRuntime.CacheInternal.Remove(key); #if DBG Debug.Trace("OutputCache", "RemoveFragment(" + key + "," + providerName + ")"); #endif }
// remove cache vary // remove entry internal static void RemoveFromProvider(String key, String providerName) { // we know where it is. If providerName is given, // then it is in that provider. If it's not given, // it's in the internal cache. if (providerName == null) { throw new ArgumentNullException("providerName"); } OutputCacheProviderCollection providers = Providers; OutputCacheProvider provider = (providers == null) ? null : providers[providerName]; if (provider == null) { throw new ProviderException(SR.GetString(SR.Provider_Not_Found, providerName)); } provider.Remove(key); #if DBG Debug.Trace("OutputCache", "Remove(" + key + ", " + providerName + ")"); #endif }
internal static void Remove(string key, HttpContext context) { HttpRuntime.CacheInternal.Remove(key); if (context == null) { OutputCacheProviderCollection providers = Providers; if (providers != null) { foreach (OutputCacheProvider provider in providers) { provider.Remove(key); } } } else { OutputCacheProvider provider2 = GetProvider(context); if (provider2 != null) { provider2.Remove(key); } } }
void OnResolveRequestCache(object o, EventArgs args) { HttpApplication app = o as HttpApplication; HttpContext context = app != null ? app.Context : null; if (context == null) { return; } OutputCacheProvider provider = FindCacheProvider(app); string vary_key = context.Request.FilePath; CachedVaryBy varyby = provider.Get(vary_key) as CachedVaryBy; string key; CachedRawResponse c; if (varyby == null) { return; } key = varyby.CreateKey(vary_key, context); c = provider.Get(key) as CachedRawResponse; if (c == null) { return; } lock (keysCacheLock) { string invValue; if (entriesToInvalidate != null && entriesToInvalidate.TryGetValue(vary_key, out invValue) && String.Compare(invValue, key, StringComparison.Ordinal) == 0) { provider.Remove(vary_key); provider.Remove(key); entriesToInvalidate.Remove(vary_key); return; } } ArrayList callbacks = c.Policy.ValidationCallbacks; if (callbacks != null && callbacks.Count > 0) { bool isValid = true; bool isIgnored = false; foreach (Pair p in callbacks) { HttpCacheValidateHandler validate = (HttpCacheValidateHandler)p.First; object data = p.Second; HttpValidationStatus status = HttpValidationStatus.Valid; try { validate(context, data, ref status); } catch { // MS.NET hides the exception isValid = false; break; } if (status == HttpValidationStatus.Invalid) { isValid = false; break; } else if (status == HttpValidationStatus.IgnoreThisRequest) { isIgnored = true; } } if (!isValid) { OnRawResponseRemoved(key, c, CacheItemRemovedReason.Removed); return; } else if (isIgnored) { return; } } HttpResponse response = context.Response; response.ClearContent(); IList cachedData = c.GetData(); if (cachedData != null) { Encoding outEnc = WebEncoding.ResponseEncoding; foreach (CachedRawResponse.DataItem d in cachedData) { if (d.Length > 0) { response.BinaryWrite(d.Buffer, 0, (int)d.Length); continue; } if (d.Callback == null) { continue; } string s = d.Callback(context); if (s == null || s.Length == 0) { continue; } byte[] bytes = outEnc.GetBytes(s); response.BinaryWrite(bytes, 0, bytes.Length); } } response.ClearHeaders(); response.SetCachedHeaders(c.Headers); response.StatusCode = c.StatusCode; response.StatusDescription = c.StatusDescription; app.CompleteRequest(); }