4

I'm using output caching for some Index views because they contain a lot of data. I want to keep it specific for every user. because the view can differ depending on the roles.

    [OutputCache(Duration = 3600, VaryByParam = "none", Location = OutputCacheLocation.Client)]
    public ActionResult Index(string schooljaarparam) {
        return View(_db.Lesplaatsens.Where(l => l.Schooljaar.Sch_Schooljaar == schooljaarparam).OrderBy(q => q.Lpl_Gemeente).ThenBy(q => q.Lpl_Instelling).ToList());
    }

Now when someone creates a new item and returns to the Index view. How do I remove the cache of the Index page, so that the newly created item will show up in the list?

I thought this would be a common question but I did not find a solution yet.

I guess you need to use HttpResponse.RemoveOutputCacheItem() but how do I find the route. And where can I see the current cached items in the debugger?

7
  • Are you putting this on your controller? Commented Feb 4, 2011 at 14:23
  • No, this is on my Index action. Commented Feb 4, 2011 at 14:25
  • Index action => So on your controller then? Commented Feb 4, 2011 at 14:32
  • not ON, but IN yes, where else would i put this? :) Commented Feb 4, 2011 at 14:48
  • Well you could put it on the view as well using @output cache stuff. Commented Feb 4, 2011 at 14:56

1 Answer 1

2

You can't remove the cached item because it isn't there (ie you are not caching it on the server).

When you say Location = OutputCacheLocation.Client, the browser will cache the response and won't even send a new request to your server when the user asks for the same page unless the cache expires or the user specifically asks for the latest version by hitting F5.

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

2 Comments

the browser doesnt cache it really, I mean, the browser DOES cache it but still does a request to the server. the server then answers with a 304 Not Modified which tells the browser to use his own cache. if the browser returns a 200 OK then the browser will download the page...
@Stefanvds I just tested again to make sure (I'm testing with ASP.NET MVC 2). The behaviour for OutputCacheLocation.Client is like I described in the answer.

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.