public PartialCacheAttribute(string cacheProfileName)
        {
            OutputCacheProfile item = ((OutputCacheSettingsSection)WebConfigurationManager.GetSection("system.web/caching/outputCacheSettings")).OutputCacheProfiles[cacheProfileName];

            base.Duration    = item.Duration;
            base.VaryByParam = item.VaryByParam;
        }
Example #2
0
        public FeedControllerFixture()
        {
            _userRepository     = new Mock <IUserRepository>();
            _categoryRepository = new Mock <ICategoryRepository>();
            _tagRepository      = new Mock <ITagRepository>();
            _storyRepository    = new Mock <IStoryRepository>();

            var cacheProfile = new OutputCacheProfile("FeedCache")
            {
                Duration = 360
            };

            var cacheSection = new OutputCacheSettingsSection();

            cacheSection.OutputCacheProfiles.Add(cacheProfile);

            _configurationManager = new Mock <IConfigurationManager>();
            _configurationManager.Setup(c => c.GetSection <OutputCacheSettingsSection>(It.IsAny <string>())).Returns(cacheSection);

            _controller = new FeedController(_configurationManager.Object, _categoryRepository.Object,
                                             _tagRepository.Object, _storyRepository.Object)
            {
                Settings       = settings.Object,
                UserRepository = _userRepository.Object
            };

            _controller.MockHttpContext("/Kigg", null, null);

            RouteTable.Routes.Clear();
            new RegisterRoutes(settings.Object).Execute();
        }
            /// <summary>
            /// Gets cache information for the specified domain operation entry.
            /// </summary>
            /// <param name="method">The domain operation entry to get cache information for.</param>
            /// <returns>Cache information.</returns>
            private static OutputCacheAttribute GetOutputCacheInformation(DomainOperationEntry method)
            {
                OutputCacheAttribute cacheAttribute = method.Attributes.OfType <OutputCacheAttribute>().FirstOrDefault();

                if (cacheAttribute != null)
                {
                    if (!String.IsNullOrEmpty(cacheAttribute.CacheProfile))
                    {
                        if (QueryOperationInvoker.cacheProfiles == null)
                        {
                            lock (QueryOperationInvoker.syncRoot)
                            {
                                if (QueryOperationInvoker.cacheProfiles == null)
                                {
                                    OutputCacheSettingsSection outputCacheSettings = (OutputCacheSettingsSection)WebConfigurationManager.GetWebApplicationSection("system.web/caching/outputCacheSettings");
                                    QueryOperationInvoker.cacheProfiles = outputCacheSettings.OutputCacheProfiles;
                                }
                            }
                        }

                        OutputCacheProfile   profile   = QueryOperationInvoker.cacheProfiles[cacheAttribute.CacheProfile];
                        OutputCacheAttribute cacheInfo = new OutputCacheAttribute(QueryOperationInvoker.GetCacheLocation(profile.Location), profile.Duration);
                        cacheInfo.VaryByHeaders        = profile.VaryByHeader;
                        cacheInfo.SqlCacheDependencies = profile.SqlDependency;
                        return(cacheInfo);
                    }

                    return(cacheAttribute);
                }
                return(null);
            }
        public PartialCacheAttribute(string cacheProfileName)
        {
            OutputCacheSettingsSection outputCacheSettingsSection = (OutputCacheSettingsSection)WebConfigurationManager.GetSection("system.web/caching/outputCacheSettings");
            OutputCacheProfile         outputCacheProfile         = outputCacheSettingsSection.OutputCacheProfiles[cacheProfileName];

            Duration    = outputCacheProfile.Duration;
            VaryByParam = outputCacheProfile.VaryByParam;
        }
Example #5
0
        public PipelineHandler(IContentPipeline pipeline)
        {
            _pipeline = pipeline;

            var settings = WebConfigurationManager.GetWebApplicationSection(
                "system.web/caching/outputCacheSettings") as OutputCacheSettingsSection;

            _cacheProfile = settings.OutputCacheProfiles[CacheProfileName] ?? CreateDefaultCacheProfile();
        }
        public CustomizeCacheAttribute(string cacheProfileName)
        {
            OutputCacheSettingsSection cacheSettings =
                (OutputCacheSettingsSection)WebConfigurationManager
                .GetSection("system.web/caching/outputCacheSettings");
            OutputCacheProfile cacheProfile = cacheSettings.OutputCacheProfiles[cacheProfileName];

            Duration     = cacheProfile.Duration;
            VaryByParam  = cacheProfile.VaryByParam;
            VaryByCustom = cacheProfile.VaryByCustom;
        }
        public int GetCacheDuration()
        {
            int        duration = 0;
            StackFrame frame    = new StackFrame(2, false);

            MethodBase method = frame.GetMethod();

            // First try the Method attribute
            OutputCacheAttribute[] attributes = (OutputCacheAttribute[])method.GetCustomAttributes(typeof(OutputCacheAttribute), true);

            // If not found, then try class
            if (attributes.Length == 0)
            {
                attributes = (OutputCacheAttribute[])GetType().GetCustomAttributes(typeof(OutputCacheAttribute), true);
            }

            if (attributes.Length > 0)
            {
                OutputCacheAttribute cacheAttribute = attributes[0];

                if (cacheAttribute.Duration > 0)
                {
                    duration = cacheAttribute.Duration;
                }
                else
                {
                    if (!string.IsNullOrEmpty(cacheAttribute.CacheProfile))
                    {
                        OutputCacheSettingsSection settings = _configurationManager.GetSection <OutputCacheSettingsSection>("system.web/caching/outputCacheSettings");

                        if ((settings != null) && (settings.OutputCacheProfiles.Count > 0))
                        {
                            OutputCacheProfile profile = settings.OutputCacheProfiles.Get(cacheAttribute.CacheProfile);

                            if ((profile != null) && (profile.Duration > 0))
                            {
                                duration = profile.Duration;
                            }
                        }
                    }
                }
            }

            if (duration > 0)
            {
                duration = Convert.ToInt32(duration / 60);
            }

            return(duration);
        }
Example #8
0
 public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
 {
     if (this.CacheProfile == null)
     {
         this.CacheProfile               = new OutputCacheProfile("temp");
         this.CacheProfile.Duration      = this.Duration;
         this.CacheProfile.NoStore       = this.NoStore;
         this.CacheProfile.SqlDependency = this.SqlDependency;
         this.CacheProfile.Location      = this.Location;
         this.CacheProfile.VaryByCustom  = this.VaryByCustom;
         this.CacheProfile.VaryByHeader  = this.VaryByHeader;
         this.CacheProfile.VaryByParam   = this.VaryByParam;
     }
     dispatchOperation.ParameterInspectors.Add(new CachingParameterInspector(this.CacheProfile));
 }
Example #9
0
        private void CacheSetting(string settingKey, string settingValue, Cache cache)
        {
            settingValue = settingValue.NullSafe();
            OutputCacheSettingsSection outputCacheSection =
                _configurationAdapter.GetSection <OutputCacheSettingsSection>("system.web/caching/outputCacheSettings");

            if (outputCacheSection.OutputCacheProfiles.Count > 0)
            {
                OutputCacheProfile profile = outputCacheSection.OutputCacheProfiles.Get("SettingsCacheProfile");
                if (null != profile)
                {
                    cache.Add(settingCacheKey + settingKey, settingValue, null, Cache.NoAbsoluteExpiration,
                              TimeSpan.FromSeconds(profile.Duration), CacheItemPriority.Normal, null);
                }
            }
        }
        public CachingParameterInspector(string cacheProfileName)
        {
            if (string.IsNullOrEmpty(cacheProfileName))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.CacheProfileNameNullOrEmpty));
            }

            OutputCacheSettingsSection cacheSettings = AspNetEnvironment.Current.UnsafeGetConfigurationSection("system.web/caching/outputCacheSettings") as OutputCacheSettingsSection;

            if (cacheSettings == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.CacheProfileNotConfigured, cacheProfileName)));
            }

            this.cacheProfile = cacheSettings.OutputCacheProfiles[cacheProfileName];
            if (this.cacheProfile == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.CacheProfileNotConfigured, cacheProfileName)));
            }

            // Validate the cacheProfile
            if (this.cacheProfile.Location != OutputCacheLocation.None)
            {
                // Duration must be set; Duration default value is -1
                if (this.cacheProfile.Duration == -1)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.CacheProfileValueMissing, this.cacheProfile.Name, "Duration")));
                }
                if (this.cacheProfile.VaryByParam == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.CacheProfileValueMissing, this.cacheProfile.Name, "VaryByParam")));
                }
            }

            if (string.Equals(this.cacheProfile.SqlDependency, "CommandNotification", StringComparison.OrdinalIgnoreCase))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR2.CommandNotificationSqlDependencyNotSupported));
            }

            if (!string.IsNullOrEmpty(this.cacheProfile.SqlDependency))
            {
                ParseSqlDependencyString(cacheProfile.SqlDependency);
            }
        }
Example #11
0
        public void Validate(OperationDescription operationDescription)
        {
/*            if (!ServiceHostingEnvironment.AspNetCompatibilityEnabled)
 *          {
 *              throw new NotSupportedException("WebCacheAttribute is supported only in AspNetCompatibility mode.");
 *          }
 */
            if (operationDescription.Behaviors.Find <WebGetAttribute>() == null)
            {
                throw new InvalidOperationException("The WebCacheAttribute can only be used with GET operations.");
            }
            if (!string.IsNullOrEmpty(this.CacheProfileName))
            {
                OutputCacheProfile         cacheProfile  = null;
                OutputCacheSettingsSection cacheSettings = (OutputCacheSettingsSection)WebConfigurationManager.GetSection("system.web/caching/outputCacheSettings");
                if (cacheSettings == null)
                {
                    throw new InvalidOperationException(String.Format("Cache profile with name '{0}' is not configured.", this.CacheProfileName));
                }
                cacheProfile = cacheSettings.OutputCacheProfiles[this.CacheProfileName];
                if (cacheProfile == null)
                {
                    throw new InvalidOperationException(String.Format("Cache profile with name '{0}' is not configured.", this.CacheProfileName));
                }
                if (!cacheProfile.Enabled)
                {
                    throw new InvalidOperationException(String.Format("Cache profile with name '{0}' is disabled.", this.CacheProfileName));
                }
                this.CacheProfile = cacheProfile;
            }
            if (string.Equals(this.SqlDependency, "CommandNotification", StringComparison.OrdinalIgnoreCase))
            {
                throw new NotSupportedException("CommandNotification is not supported as a valid sql dependency currently");
            }
            // validate that the dependency has been properly configured in sql
            if (!string.IsNullOrEmpty(this.SqlDependency))
            {
                foreach (SqlCacheDependency dependency in CachingParameterInspector.CreateSqlDependencies(this.SqlDependency))
                {
                    dependency.Dispose();
                }
            }
        }
Example #12
0
    public ChildActionOutputCacheAttribute(string cacheProfile)
    {
        // get output cache section of web config
        OutputCacheSection settings = (OutputCacheSection)WebConfigurationManager.GetSection($"{_cachingSection}{_outputCacheSection}");

        // check section exists and caching is enabled
        if (settings != null && settings.EnableOutputCache)
        {
            // if caching enabled, get profile
            OutputCacheSettingsSection profileSettings = (OutputCacheSettingsSection)WebConfigurationManager.GetSection($"{_cachingSection}{_profileSection}");
            OutputCacheProfile         profile         = profileSettings.OutputCacheProfiles[cacheProfile];
            if (profile != null && profile.Enabled)
            {
                // if profile exits set profile params
                Duration        = profile.Duration;
                VaryByParam     = profile.VaryByParam;
                VaryByCustom    = profile.VaryByCustom;
                _profileEnabled = true;               // set profile enable to true as output cache is turned on and there is a profile
            }
        }
    }
	// Methods
	public void Add(OutputCacheProfile name) {}
	public void Set(OutputCacheProfile user) {}
 public CachingParameterInspector(OutputCacheProfile cacheProfile)
 {
     this.cacheProfile = cacheProfile;
 }
 public void Set(OutputCacheProfile user)
 {
 }
 // Methods
 public void Add(OutputCacheProfile name)
 {
 }