I did a GetVaryByCustomString that returns:
context.User.Identity.IsAuthenticated.ToString();
But I have a big problem, imagine this flow:
The user(or anyone) access the home page. GetVaryByCustomString will return "false" and cache that. Every time that somebody ask if home page changed, will return 304.
I login at site and go to Home Page, GetVaryByCustomString returns "true" then cache isn´t used. Every time that I go to Home Page, ASP.NET returns me 304.
I logout, and go to Home Page, now GetVaryByCustomString returns 304, because of step one, but the OutputCache don´t know that the cache that I have, is from logged user.
If I press Ctrl+F5, it works, since that the problem is in browser/server, the server side cache is OK. But it return 304, and I have a logged page cached.
There is any solution? Or do I need to stop caching authenticated users?
UPDATE: I think that cache for mutable values just doesn´t work. It need that browsers do they cache by this values too....And don´t exists Vary by Cookies...
What we did eventually is what most websites including SO does: cache the page with ZERO info about current user.
Using AJAX, get who's the current user and manipulate the page according to them.
Example: follow/unfollow button on a member profile. Render the cached page with no logic of who's the current user implemented. Once the page loads, hit the server with an AJAX checking whether the current user is following or not and accordingly change the button state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With