Dr.Denis McCracleJizz
Dr.Denis McCracleJizz

Reputation: 870

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.

Upvotes: 3

Views: 263

Answers (2)

M. Mennan Kara
M. Mennan Kara

Reputation: 10222

Without the Location property, in addition to the server side caching, the output cache provider also tells the client (browser) to cache the response for the duration given on the attribute properties. To prevent this you need to use the Location property of the OutputCacheAttribute

Changing your attribute to this will solve your problem:

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

Upvotes: 1

FAtBalloon
FAtBalloon

Reputation: 4500

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

Upvotes: 2

Related Questions