static OutputCache() { DefaultOptions = OutputCacheOptions.None; var providerSettings = new CacheSettingsManager().RetrieveOutputCacheProviderSettings(); if (providerSettings == null || providerSettings.Type == null) { Instance = new MemoryCacheProvider(); } else { try { Instance = (OutputCacheProvider)Activator.CreateInstance(Type.GetType(providerSettings.Type)); Instance.Initialize(providerSettings.Name, providerSettings.Parameters); } catch (Exception ex) { throw new ConfigurationErrorsException( string.Format("Unable to instantiate and initialize OutputCacheProvider of type '{0}'. Make sure you are specifying the full type name.", providerSettings.Type), ex ); } } }
/// <summary> /// Builds the cache settings. /// </summary> /// <returns></returns> /// <exception cref="System.Web.HttpException"> /// The 'duration' attribute must have a value that is greater than or equal to zero. /// </exception> protected CacheSettings BuildCacheSettings() { CacheSettings cacheSettings; if (string.IsNullOrEmpty(CacheProfile)) { cacheSettings = new CacheSettings { IsCachingEnabled = CacheSettingsManager.IsCachingEnabledGlobally, Duration = Duration, VaryByCustom = VaryByCustom, VaryByParam = VaryByParam, Location = (int)Location == -1 ? OutputCacheLocation.Server : Location, NoStore = NoStore, Options = Options, AnonymousOnly = AnonymousOnly, }; } else { var cacheProfile = CacheSettingsManager.RetrieveOutputCacheProfile(CacheProfile); cacheSettings = new CacheSettings { IsCachingEnabled = CacheSettingsManager.IsCachingEnabledGlobally && cacheProfile.Enabled, Duration = Duration == -1 ? cacheProfile.Duration : Duration, VaryByCustom = VaryByCustom ?? cacheProfile.VaryByCustom, VaryByParam = VaryByParam ?? cacheProfile.VaryByParam, Location = (int)Location == -1 ? ((int)cacheProfile.Location == -1 ? OutputCacheLocation.Server : cacheProfile.Location) : Location, NoStore = _noStore.HasValue ? _noStore.Value : cacheProfile.NoStore, Options = Options, AnonymousOnly = AnonymousOnly, }; } if (cacheSettings.Duration == -1) { throw new HttpException("The directive or the configuration settings profile must specify the 'duration' attribute."); } if (cacheSettings.Duration < 0) { throw new HttpException("The 'duration' attribute must have a value that is greater than or equal to zero."); } return(cacheSettings); }