3

I thought this would be a simple thing but it's driving me nuts. I simply added the following...

[OutputCache(Duration = 300)]

before an action

public ViewResult Index(string parameter) {...}

But it's not caching it, I put a breakpoint in the debugger inside the action and it hits it every time I go to that page. It does work if I set the Location parameter to Client but I want it to be server based. Do I have to enable caching somewhere else for it to work?

1
  • if it matters, the parameter comes from the router, as in routes.MapRoute(null, "{parameter}", new { controller = "mycontroller", action = "index" }) Commented Nov 4, 2013 at 21:29

3 Answers 3

9

Found the problem. The Base controller set a cookie in OnActionExecuting, and I found out that a page that sets a cookie doesn't get stored in the output cache, so basically pages were not being cached regardless of the [OutputCache] directive.

Sign up to request clarification or add additional context in comments.

1 Comment

What did you do to solve your issue? Did you keep the action filter and if so did you still pursue caching?
0

I had the same issue, I solved this problem by fixing the exact parameter at the argument VaryByParam.

[OutputCache(Duration=120, VaryByParam ="argument1")]

Do this instead of VaryByParam ="*"

Comments

0

I got this issue in my project and find out a solution. In BaseController (It may be a generic controller though), Some others developer added an attribute [DisableCache] to disable cache and after removing that attribute from base controller, [OutputCache] worked fine.

    //[DisableCache]
    public class BaseController : Controller
    { 
    }
  
    [OutputCache(Location = OutputCacheLocation.Any,Duration = int.MaxValue, VaryByParam = "none")]
    public ActionResult GetIntegratedModules()
    {
        var applications = cacheManagerService.GetAllAspNetApplications();

        var model = new IntegratedModuleListViewModel
        {
            Applications = applications
        };

        return PartialView("_IntegratedModulesPartial", model);
    } 

Hope this clue will helpful for others. Thanks!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.