Class ContentOutputCacheAttribute

Attribute that can be used to specify that the output from a action should be put in output cache.

Inheritance
System.Object
ContentOutputCacheAttribute
Namespace: EPiServer.Web.Mvc
Assembly: EPiServer.dll
Version: 8.11.0
Syntax
public class ContentOutputCacheAttribute : OutputCacheAttribute
Remarks

This attibute cannot be used on child actions. The reason for this is that in MVC child actions are output cached in a memory cache and hence the output cache will not be invalidated when a content is changed.

The output cache is turned on based on the following criteria:

1. The httpCacheExpiration in web.config is > 0.

2. The current user must not be logged on, aka Anonymous.

3. The request must be a GET type request. Hence, Postbacks and form postings will not be cached.

4. The current content must be the published version (the WorkID is == 0).

Some cache parameters are fetched from configruation if not present on attribute. More specifically if Duration is 0 then the httpCacheExpiration (on element/episerver/sites/site/SiteSetting) value from web.config is used. And if VaryByCustom is null or empty then httpCacheVaryByCustom (on element/episerver/sites/site/SiteSetting) value from web.config is used. Cache item expiration is set to the httpCacheExpiration setting, which is the number of seconds the item should reside in the cache, as long as the IVersionable.StopPublish value of the content is not less than the policy timeout (in which case, the StopPublish value is used).

Constructors

ContentOutputCacheAttribute()

Initializes a new instance of the ContentOutputCacheAttribute class.

Declaration
public ContentOutputCacheAttribute()

Properties

ConfigurationSettings

Gets or sets the configuration settings.

Declaration
public Injected<Settings> ConfigurationSettings { get; set; }
Property Value
Type Description
Injected<Settings>

The configuration settings.

ContentLoader

Gets or sets the content loader.

Declaration
public Injected<IContentLoader> ContentLoader { get; set; }
Property Value
Type Description
Injected<IContentLoader>

The content loader.

Disable

Gets or sets a value indicating whether this ContentOutputCacheAttribute is disabled.

Declaration
public virtual bool Disable { get; set; }
Property Value
Type Description
System.Boolean

true if disable; otherwise, false.

Remarks

This value is mainly used when a baseclass specifies that output cache should be used, then a subclass can put the attribute with Disable=true to prevent output cache to be used for the subclass.

UseOutputCacheValidator

Gets or sets the use output cache validator.

Declaration
public virtual Func<IPrincipal, HttpContextBase, TimeSpan, bool> UseOutputCacheValidator { get; set; }
Property Value
Type Description
System.Func<System.Security.Principal.IPrincipal, System.Web.HttpContextBase, System.TimeSpan, System.Boolean>

The use output cache validator.

Remarks

This is the function that is called to evaluate if a request should be added to output cache. The default implementation calls UseOutputCache(IPrincipal, HttpContextBase, TimeSpan).

Methods

OnActionExecuting(ActionExecutingContext)

This method is an implementation of System.Web.Mvc.IActionFilter.OnActionExecuting(System.Web.Mvc.ActionExecutingContext) and supports the ASP.NET MVC infrastructure. It is not intended to be used directly from your code.

Declaration
public override void OnActionExecuting(ActionExecutingContext filterContext)
Parameters
Type Name Description
System.Web.Mvc.ActionExecutingContext filterContext

The filter context.

OnResultExecuting(ResultExecutingContext)

Called before the action result executes.

Declaration
public override void OnResultExecuting(ResultExecutingContext filterContext)
Parameters
Type Name Description
System.Web.Mvc.ResultExecutingContext filterContext

The filter context, which encapsulates information for using System.Web.Mvc.AuthorizeAttribute.

Exceptions
Type Condition
System.ArgumentNullException

The filterContext parameter is null.

Extension Methods