Output Cache Not Working

Output cache should be enabled for your ASP.NET website so that it can scale well during high load. Having output cache disabled means that your server(s) need to re-render each page for each request. In low traffic scenarios, this might work ok, however, under high load you may see the CPU spike to dangerous levels. 

For details on how output caching works, see Output Caching.

Agility.Web enables Output Cache by default, using the default ASP.NET Output Cache provider. While you typically don't need to do anything to have Output Cache working, there can be scenarios where the Output Cache can be disabled due to logic within your application.

This article will serve as a guide as to how you can test Output Caching, and things to look for in your application that might be overriding it.

Testing Output Cache

The first step is to reliably test output cache. You can do this by viewing the source of a deployed Agility website running in live mode. When viewing the source html, you'll see a timestamp being outputted in the <head>. This represents the last time this page was rendered by the server.

<meta name="agility_timestamp" content="2018-12-20 04:15:28 PM" />
<meta name="agility_attributes" content="Mode=Live, IsPreview=False, Language=en-ca, Machine=RD0004FF9D2AE8, CustomOutputCache=False" />

Testing output cache is a simple as refreshing the page over and over. If the timestamp continually updates AND is on the same machine then this means output cache is not working. The duration of how long a page is kept in cache is defined in Agility > Settings > Caching.

Normally, you would want a value that is at least 300 seconds (5 minutes).

Troubleshooting Caching

The following are some known causes to prevent output cache from working:

  1. Website is setting cookies server-side - if you have any code that is setting Response.Cookies on a page request, that page will never be set Output Cached.

  2. Url is being rewritten within the application - if you have code that is re-writing the path within the app, then that page will also never be cached.

  3. Low memory - if your web server does not have enough memory, this will affect how many pages can be kept in cache and for how long. 

  4. Misconfigured Override - you can overried how pages are Output Cached and this is typical, however if you set your output cache key to be something that is ALWAYS dynamic then your output cache will never work.

    public override string GetVaryByCustomString(HttpContext context, string custom)
                 * Handle OutputCache
                 * AgilityCacheControl is a special "VaryByCustom" value that is added in the Agility Controller
                if (string.Compare(custom, "AgilityCacheControl", true) == 0)
                    string s = Data.GetAgilityVaryByCustomString(context);
                    s = string.Format("{0}.{1}", s, context.Request.Url.Host);
                    return s;
                return base.GetVaryByCustomString(context, custom);
  5. Website not in Live Mode - if your website is deployed in Development Mode or you are in a private Preview Session, then by design, Output Cache will not be working

  6. Output Cache is disabled in Agility - you can enable/disable output caching in Agility > Settings > Caching. You can also mark certain pages in Agility as being excluded from Output Cache - this can be found on the Settings tab of the page in the page tree in Agility.

  7. You are setting AgilityContext.LanguageCode in a method that is running on all requests.


Testing Locally

You can test Output Cache locally by copying the Live Content files from your web server, or copy your Staging Content files into your local Live Content folder in your content repository and running the website locally using DevelopmentMode=False.


1 out of 1 found this helpful



Please sign in to leave a comment.