Search code examples
c#asp.net-mvccachingoutput-caching

Disable outputcaching


I have an actionResult that I've added caching to.

[OutputCache(Duration = 120)]

When I change some elements on the page, that is cached, I want to remove the cached output. Here is what I didL

public void RemoveCachingForProfile(string guid)
{
    HttpResponse.RemoveOutputCacheItem("/Profile/" + guid);
}

When I change something in my page, I go through the RemoveCachingForProfile function. Then, when I come back on my Profile's page, it still shows what's in the cache, even tho I disabled it.

If i hit f5 it shows the correct output. It seems to be the browser that is caching the page.


Solution

  • You have to store the Cache on the server instead of the local machine:

    [OutputCache(Location = OutputCacheLocation.Server, Duration = 120)]
    

    Here's the dependancy:

    System.Web.UI