views:

804

answers:

2

In my ASP.net MVC application, I've got several views that I'd like to set to save in the browser's cache. I've got the methods built to do it, but here's my issue.

The menu in my site is different between logged in and logged off visitors. If the logged in page is cached, then even when the user logs off the menu remains in the logged in mode. It's actually not, but on that visitor's browser it is.

How can I go about clearing/expiring that cache so the visitor's browser updates when I need it to, yet still be able to make use of browser cache?

Thanks in advance!

A: 

You can do it with an AutoRefresh attribute on your action method. Here are some examples:

[AutoRefresh(ControllerName = "Home", ActionName = "About", DurationInSeconds = 10)] 
public ActionResult Index1() 
{
}
AutoRefresh(ActionName = "About", DurationInSeconds = 15)] 
public ActionResult Index2() 
{
}
[AutoRefresh(RouteName = "ByFavoriteRoute", DurationInSeconds = 30)] 
public ActionResult Index3() 
{
}
[AutoRefresh(DurationInSeconds = 45)] 
public ActionResult Index4()
{
}
Robert Harvey
+2  A: 

For HTML pages it's difficult. I turned off client caching for that same reason, and tried to make the server caching as efficient as possible. I now use OutputCache with VaryByCustom set to the login status.

We ran some load tests on that system and the only bottleneck is the bandwidth that this generates.

And on a side note: I used donut-caching for the login status. But I was not able to get it to work with dynamic compression (to reduce the bandwidth bottleneck mentioned above)

See also this question

chris166