Exemplo n.º 1
0
 // add ControlCachedVary
 private static ControlCachedVary UtcAdd(String key, ControlCachedVary cachedVary)
 {
     return((ControlCachedVary)HttpRuntime.CacheInternal.UtcAdd(key,
                                                                cachedVary,
                                                                null /*dependencies*/,
                                                                Cache.NoAbsoluteExpiration,
                                                                Cache.NoSlidingExpiration,
                                                                CacheItemPriority.Normal,
                                                                null /*callback*/));
 }
Exemplo n.º 2
0
        // insert fragment
        internal static void InsertFragment(String cachedVaryKey, ControlCachedVary cachedVary,
                                            String fragmentKey, PartialCachingCacheEntry fragment,
                                            CacheDependency dependencies,
                                            DateTime absExp, TimeSpan slidingExp,
                                            String providerName)
        {
            // if providerName is not null, find the provider in the collection.
            // if providerName is null, use default provider.
            // if the default provider is undefined or the fragment can't be inserted in the
            // provider, insert it in the internal cache.
            OutputCacheProvider provider = GetFragmentProvider(providerName);

            //
            // ControlCachedVary and PartialCachingCacheEntry can be serialized
            //

            bool useProvider = (provider != null);

            if (useProvider)
            {
                bool canUseProvider = (slidingExp == Cache.NoSlidingExpiration &&
                                       (dependencies == null || dependencies.IsFileDependency()));

                if (useProvider && !canUseProvider)
                {
                    throw new ProviderException(SR.GetString(SR.Provider_does_not_support_policy_for_fragments, providerName));
                }
            }

#if DBG
            bool cachedVaryPutInCache = (cachedVary != null);
#endif
            if (cachedVary != null)
            {
                // Add the ControlCachedVary item so that a request will know
                // which varies are needed to issue another request.

                // Use the Add method so that we guarantee we only use
                // a single ControlCachedVary and don't overwrite existing ones.
                ControlCachedVary cachedVaryInCache;
                if (!useProvider)
                {
                    cachedVaryInCache = OutputCache.UtcAdd(cachedVaryKey, cachedVary);
                }
                else
                {
                    cachedVaryInCache = (ControlCachedVary)provider.Add(cachedVaryKey, cachedVary, Cache.NoAbsoluteExpiration);
                }

                if (cachedVaryInCache != null)
                {
                    if (!cachedVary.Equals(cachedVaryInCache))
                    {
                        // overwrite existing cached vary
                        if (!useProvider)
                        {
                            HttpRuntime.CacheInternal.UtcInsert(cachedVaryKey, cachedVary);
                        }
                        else
                        {
                            provider.Set(cachedVaryKey, cachedVary, Cache.NoAbsoluteExpiration);
                        }
                    }
                    else
                    {
                        cachedVary = cachedVaryInCache;
#if DBG
                        cachedVaryPutInCache = false;
#endif
                    }
                }

                if (!useProvider)
                {
                    AddCacheKeyToDependencies(ref dependencies, cachedVaryKey);
                }

                // not all caches support cache key dependencies, but we can use a "change number" to associate
                // the ControlCachedVary and the PartialCachingCacheEntry
                fragment._cachedVaryId = cachedVary.CachedVaryId;
            }

            // Now insert into the cache (use cache provider if possible, otherwise use internal cache)
            if (!useProvider)
            {
                HttpRuntime.CacheInternal.UtcInsert(fragmentKey, fragment,
                                                    dependencies,
                                                    absExp, slidingExp,
                                                    CacheItemPriority.Normal,
                                                    null);
            }
            else
            {
                string depKey = null;
                if (dependencies != null)
                {
                    depKey = OUTPUTCACHE_KEYPREFIX_DEPENDENCIES + dependencies.GetUniqueID();
                    fragment._dependenciesKey = depKey;
                    fragment._dependencies    = dependencies.GetFileDependencies();
                }
                provider.Set(fragmentKey, fragment, absExp);
                if (dependencies != null)
                {
                    // use Add and dispose dependencies if there's already one in the cache
                    Object d = HttpRuntime.CacheInternal.UtcAdd(depKey, new DependencyCacheEntry(fragmentKey, null, provider.Name),
                                                                dependencies,
                                                                absExp, Cache.NoSlidingExpiration,
                                                                CacheItemPriority.Normal, s_dependencyRemovedCallbackForFragment);
                    if (d != null)
                    {
                        dependencies.Dispose();
                    }
                }
            }

#if DBG
            string cachedVaryType = (cachedVaryPutInCache) ? "ControlCachedVary" : "";
            string providerUsed   = (useProvider) ? provider.Name : "CacheInternal";
            Debug.Trace("OutputCache", "InsertFragment("
                        + cachedVaryKey + ", "
                        + cachedVaryType + ", "
                        + fragmentKey + ", PartialCachingCacheEntry, ...) -->"
                        + providerUsed);
#endif
        }
Exemplo n.º 3
0
        internal static void InsertFragment(string cachedVaryKey, ControlCachedVary cachedVary, string fragmentKey, PartialCachingCacheEntry fragment, CacheDependency dependencies, DateTime absExp, TimeSpan slidingExp, string providerName)
        {
            OutputCacheProvider fragmentProvider = GetFragmentProvider(providerName);
            bool flag = fragmentProvider != null;

            if (flag)
            {
                bool flag2 = (slidingExp == Cache.NoSlidingExpiration) && ((dependencies == null) || dependencies.IsFileDependency());
                if (flag && !flag2)
                {
                    throw new ProviderException(System.Web.SR.GetString("Provider_does_not_support_policy_for_fragments", new object[] { providerName }));
                }
            }
            if (cachedVary != null)
            {
                ControlCachedVary vary;
                if (!flag)
                {
                    vary = UtcAdd(cachedVaryKey, cachedVary);
                }
                else
                {
                    vary = (ControlCachedVary)fragmentProvider.Add(cachedVaryKey, cachedVary, Cache.NoAbsoluteExpiration);
                }
                if (vary != null)
                {
                    if (!cachedVary.Equals(vary))
                    {
                        if (!flag)
                        {
                            HttpRuntime.CacheInternal.UtcInsert(cachedVaryKey, cachedVary);
                        }
                        else
                        {
                            fragmentProvider.Set(cachedVaryKey, cachedVary, Cache.NoAbsoluteExpiration);
                        }
                    }
                    else
                    {
                        cachedVary = vary;
                    }
                }
                if (!flag)
                {
                    AddCacheKeyToDependencies(ref dependencies, cachedVaryKey);
                }
                fragment._cachedVaryId = cachedVary.CachedVaryId;
            }
            if (!flag)
            {
                HttpRuntime.CacheInternal.UtcInsert(fragmentKey, fragment, dependencies, absExp, slidingExp, CacheItemPriority.Normal, null);
            }
            else
            {
                string key = null;
                if (dependencies != null)
                {
                    key = "aD" + dependencies.GetUniqueID();
                    fragment._dependenciesKey = key;
                    fragment._dependencies    = dependencies.GetFileDependencies();
                }
                fragmentProvider.Set(fragmentKey, fragment, absExp);
                if ((dependencies != null) && (HttpRuntime.CacheInternal.UtcAdd(key, new DependencyCacheEntry(fragmentKey, null, fragmentProvider.Name), dependencies, absExp, Cache.NoSlidingExpiration, CacheItemPriority.Normal, s_dependencyRemovedCallbackForFragment) != null))
                {
                    dependencies.Dispose();
                }
            }
        }
Exemplo n.º 4
0
 private static ControlCachedVary UtcAdd(string key, ControlCachedVary cachedVary)
 {
     return((ControlCachedVary)HttpRuntime.CacheInternal.UtcAdd(key, cachedVary, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null));
 }
Exemplo n.º 5
0
 // add ControlCachedVary
 private static ControlCachedVary UtcAdd(String key, ControlCachedVary cachedVary)
 {
     return((ControlCachedVary)HttpRuntime.Cache.InternalCache.Add(key, cachedVary, null));
 }