ASP. net mvc 1.0 OutputCacheAttribute

Source: Internet
Author: User
Tags website performance

Cache is the "killer" of website development. As a key factor in performance improvement, MVC naturally does not lack this content. However, it directly borrows the page cache mechanism of ASP. NET itself.

Public class OutputCacheAttribute: ActionFilterAttribute
{
Public override void OnResultExecuting (ResultExecutingContext filterContext)
{
...
OutputCachedPage page = new OutputCachedPage (_ cacheSettings );
Page. ProcessRequest (HttpContext. Current );
}

Private sealed class OutputCachedPage: Page
{
...
}
}

We are familiar with the usage and parameters.

[OutputCache (Duration = 10, VaryByParam = "none")]
Public ActionResult Index ()
{
Return View ();
}

However, I personally do not recommend that you write the cache parameters to the Controller cs code, because you have to re-compile the Assembly file when adjusting the cache policy. It is much easier to directly write the parameters in the. aspx file.

<% @ Page Language = "C #" Inherits = "System. Web. Mvc. ViewPage" %>
<% @ OutputCache Duration = "10" VaryByParam = "None" %>

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Index </title>
</Head>
<Body>
<% = DateTime. Now %>
</Body>
</Html>

Of course, you can also write the parameters in the configuration file so that you can combine "OutputCacheAttribute" and "Easy to modify.

[OutputCache (CacheProfile = "Index")]
Public ActionResult Index ()
{
Return View ();
}

Web. config
<System. web>
<Caching>
<OutputCacheSettings>
<OutputCacheProfiles>
<Add name = "Index" duration = "10" varyByParam = "none"/>
</OutputCacheProfiles>
</OutputCacheSettings>
</Caching>
</System. web>

We can also implement static HTML-based caching to improve website performance.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.