Share via


OutputCacheAttribute Class

 

Represents an attribute that is used to mark an action method whose output will be cached.

Namespace:   System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

Inheritance Hierarchy

System.Object
  System.Attribute
    System.Web.Mvc.FilterAttribute
      System.Web.Mvc.ActionFilterAttribute
        System.Web.Mvc.OutputCacheAttribute

Syntax

[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Method, 
    Inherited = true, AllowMultiple = false)]
public class OutputCacheAttribute : ActionFilterAttribute, IExceptionFilter
[AttributeUsageAttribute(AttributeTargets::Class | AttributeTargets::Method, 
    Inherited = true, AllowMultiple = false)]
public ref class OutputCacheAttribute : ActionFilterAttribute, 
    IExceptionFilter
[<AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Method,
    Inherited = true, AllowMultiple = false)>]
type OutputCacheAttribute = 
    class
        inherit ActionFilterAttribute
        interface IExceptionFilter
    end
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Method,
    Inherited := True, AllowMultiple := False)>
Public Class OutputCacheAttribute
    Inherits ActionFilterAttribute
    Implements IExceptionFilter

Constructors

Name Description
System_CAPS_pubmethod OutputCacheAttribute()

Initializes a new instance of the OutputCacheAttribute class.

Properties

Name Description
System_CAPS_pubproperty AllowMultiple

Gets or sets a value that indicates whether more than one instance of the filter attribute can be specified.(Inherited from FilterAttribute.)

System_CAPS_pubproperty CacheProfile

Gets or sets the cache profile name.

System_CAPS_pubpropertySystem_CAPS_static ChildActionCache

Gets or sets the child action cache.

System_CAPS_pubproperty Duration

Gets or sets the cache duration, in seconds.

System_CAPS_pubproperty Location

Gets or sets the location.

System_CAPS_pubproperty NoStore

Gets or sets a value that indicates whether to store the cache.

System_CAPS_pubproperty Order

Gets or sets the order in which the action filters are executed.(Inherited from FilterAttribute.)

System_CAPS_pubproperty SqlDependency

Gets or sets the SQL dependency.

System_CAPS_pubproperty TypeId

(Inherited from Attribute.)

System_CAPS_pubproperty VaryByContentEncoding

Gets or sets the vary-by-content encoding.

System_CAPS_pubproperty VaryByCustom

Gets or sets the vary-by-custom value.

System_CAPS_pubproperty VaryByHeader

Gets or sets the vary-by-header value.

System_CAPS_pubproperty VaryByParam

Gets or sets the vary-by-param value.

Methods

Name Description
System_CAPS_pubmethod Equals(Object)

(Inherited from Attribute.)

System_CAPS_protmethod Finalize()

(Inherited from Object.)

System_CAPS_pubmethod GetHashCode()

(Inherited from Attribute.)

System_CAPS_pubmethod GetType()

(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_static IsChildActionCacheActive(ControllerContext)

Returns a value that indicates whether a child action cache is active.

System_CAPS_pubmethod IsDefaultAttribute()

(Inherited from Attribute.)

System_CAPS_pubmethod Match(Object)

(Inherited from Attribute.)

System_CAPS_protmethod MemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethod OnActionExecuted(ActionExecutedContext)

This method is an implementation of IActionFilter.OnActionExecuted and supports the ASP.NET MVC infrastructure. It is not intended to be used directly from your code. (Overrides ActionFilterAttribute.OnActionExecuted(ActionExecutedContext).)

System_CAPS_pubmethod OnActionExecuting(ActionExecutingContext)

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

System_CAPS_pubmethod OnException(ExceptionContext)

This method is an implementation of IExceptionFilter.OnException and supports the ASP.NET MVC infrastructure. It is not intended to be used directly from your code.

System_CAPS_pubmethod OnResultExecuted(ResultExecutedContext)

This method is an implementation of IResultFilter.OnResultExecuted and supports the ASP.NET MVC infrastructure. It is not intended to be used directly from your code.(Overrides ActionFilterAttribute.OnResultExecuted(ResultExecutedContext).)

System_CAPS_pubmethod OnResultExecuting(ResultExecutingContext)

Called before the action result executes.(Overrides ActionFilterAttribute.OnResultExecuting(ResultExecutingContext).)

System_CAPS_pubmethod ToString()

(Inherited from Object.)

Explicit Interface Implementations

Name Description
System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfoCount(UInt32)

(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

(Inherited from Attribute.)

Remarks

Output caching lets you store the output of an action method in memory on the Web server. For example, if the action method renders a view, the view page will be cached. This cached page is then available to the application for subsequent requests. Output caching saves your application the time and resources it would take to re-create the result of the action method.

In ASP.NET MVC, you can use the OutputCacheAttribute attribute to mark action methods whose output you want to cache. If you mark a controller with the OutputCacheAttribute attribute, the output of all action methods in the controller will be cached.

The properties contained in OutputCacheAttribute are almost the same as the properties of the @ OutputCache directive. The only @ OutputCache property that is not supported by OutputCacheAttribute is VaryByControl.

Using a Cache Profile

To avoid code duplication, you can set a cache profile in the Web.config file instead of setting cache values individually in pages. You can then reference the profile by using the CacheProfile property of the OutputCache attribute. The following example shows a section of a Web.config file that sets a cache profile. This cache profile will apply to all pages unless the page overrides these settings.

<system.web>
  <caching>
    <outputCacheSettings>
      <outputCacheProfiles>
        <add name="MyProfile" duration="60" varyByParam="*" />
      </outputCacheProfiles>
    </outputCacheSettings>
  </caching>
</system.web>

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

System.Web.Mvc Namespace

Return to top