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?

Stefanvds
  • 5,868
  • 5
  • 48
  • 72

1 Answers1

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.

Çağdaş Tekin
  • 16,592
  • 4
  • 49
  • 58
  • 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 Feb 06 '11 at 10:03
  • @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. – Çağdaş Tekin Feb 06 '11 at 10:33