Exemple #1
0
        // only used by providers
        private static void DependencyRemovedCallbackForFragment(string key, object value, CacheItemRemovedReason reason)
        {
            Debug.Trace("OutputCache", "DependencyRemovedCallbackForFragment: reason=" + reason + ", key=" + key);

            if (reason == CacheItemRemovedReason.DependencyChanged)
            {
                DependencyCacheEntry dce = value as DependencyCacheEntry;
                if (dce.OutputCacheEntryKey != null)
                {
                    try {
                        OutputCache.RemoveFragment(dce.OutputCacheEntryKey, dce.ProviderName);
                    }
                    catch (Exception e) {
                        HandleErrorWithoutContext(e);
                    }
                }
            }
        }
Exemple #2
0
        // lookup fragment
        internal static Object GetFragment(String key, String providerName)
        {
            // if providerName is null, use default provider.
            // if providerName is not null, get it from the provider collection.
            // if it's not in the provider or the default provider is undefined,
            // check the internal cache (we don't know where it is).
            Object result = null;
            OutputCacheProvider provider = GetFragmentProvider(providerName);

            if (provider != null)
            {
                result = provider.Get(key);
                PartialCachingCacheEntry fragment = result as PartialCachingCacheEntry;
                if (fragment != null)
                {
                    if (HasDependencyChanged(true /*isFragment*/, fragment._dependenciesKey, fragment._dependencies, null /*kernelKey*/, key, provider.Name))
                    {
                        OutputCache.RemoveFragment(key, provider.Name);
#if DBG
                        Debug.Trace("OutputCache", "GetFragment(" + key + "," + providerName + ") --> null, " + providerName);
#endif
                        return(null);
                    }
                }
            }

            if (result == null)
            {
                result = HttpRuntime.CacheInternal.Get(key);
#if DBG
                string typeName = (result != null) ? result.GetType().Name : "null";
                Debug.Trace("OutputCache", "GetFragment(" + key + "," + providerName + ") --> " + typeName + ", CacheInternal");
            }
            else
            {
                Debug.Trace("OutputCache", "GetFragment(" + key + "," + providerName + ") --> " + result.GetType().Name + ", " + providerName);
#endif
            }
            return(result);
        }