0

I have a Controller/Action called "List". This method has built-in with attribute

[OutputCache(Duration = 3600, VaryByParam = "*")]

This action have cache of 3600 seconds, because load data from database and it are changed a each 1 hour (more/less).

The problem it's on Layout.cshtml, because my master layout (its my master page), show on header top bar the UserName if authenticated user or show the static text User when the user isn't authenticated. See the code below:

@Html.Raw(WebSecurity.IsAuthenticated ? WebSecurity.CurrentUserName : "User")

When anybody is authenticated the name of the first access on page the cache is done, then all user, authenticated or no authenticated, see on header top bar, the username of the first authenticated user. This is very bad!

I thought that would not be done layout.cshtml cache, only the data from the Controller/Action specified.

How I fix it?

I don´t like to remove the OutputCache because it´s very important for me. The header top bar is common for all user because has built-in in layout page.

Jeferson Tenorio
  • 2,030
  • 25
  • 31

1 Answers1

1

I think what you are trying to achieve is Donut Caching, caching all the page except a section. I'm not sure whether MVC supports this (MVC 3 - no). There is an open source available DevTrends.MvcDonutCaching that 'll help you.

VJAI
  • 32,167
  • 23
  • 102
  • 164