Valamas
Valamas

Reputation: 24759

Why wont my application cache using OutputCache

I am at a loss to explain why my application is not caching the front page.

I have placed a datestamp on the page: @DateTime.Now

Here is the Home controller action

[OutputCache(Duration = 60)]
public ActionResult Index()
{
    return View();
}

However, caching is not working and the front page keeps changing the date.

I have tried to reduce the front page and associated layouts to bare minimum so only the DateTime.Now was being stamped.

I have inspected all base controllers for any disable caching code.

Also inspected the global.asax

Inspected the web.config for any caching configuration - none.

Inspected with fiddler. Here is the response header.

HTTP/1.1 200 OK
Cache-Control: public, no-cache="Set-Cookie", max-age=60
Content-Type: text/html; charset=utf-8
Expires: Wed, 04 Mar 2015 05:20:45 GMT
Last-Modified: Wed, 04 Mar 2015 05:19:45 GMT
Vary: *

I have also tried different browsers that would not have any local caching settings modified.

Have also tried deploying the app to a stage server so it is not run on my dev machine.

Have tried making a fresh asp.net mvc application. That did work. Somewhat helpful in at least telling me the technology works.

Where could the problem be?

Upvotes: 1

Views: 675

Answers (1)

Nick
Nick

Reputation: 5892

A couple of things to check:

  1. If this is on your production environment, check output caching is enabled on IIS. See this page.

  2. Try switching the location of your cache to help narrow down where the issue lies:

e.g.

[OutputCache(Duration = 60, Location = OutputCacheLocation.Server)]
[OutputCache(Duration = 60, Location = OutputCacheLocation.Client)]
  1. Check your web.config for any [caching] entries which may override default behaviour

Upvotes: 2

Related Questions