I want to use an Enum value for the types of VaryByCustom parameters I will support, is it possible to do this?
I tried setting it in the page itself
<%@ OutputCache Duration="600" VaryByParam="none"
VaryByCustom='<%=VaryByCustomType.IsAuthenticated.ToString(); %>' %>
But this returned the entire literal string "<%=VaryByCustomType.IsAuthenticated.ToString(); %>"
inside my global.asax
is there any way to do this either on the page itself or from the codebehind? Or is this just something I have to accept is purely magic strings and nothing I can do to add type safety to it?
Page Output caching enables caching of individual web pages. Post-Cache Substitution exempts fragments of a web page from caching. With cache profiles, cache settings can be specified for a group of web pages. The <ouputCache> and <outputCacheSettings> elements in Web.Config files are used to configure cache settings in Page Output Caching.
In this article you will learn everything about Output Caching in MVC. Output Caching enables us to cache the content returned by any controller method so that the same content does not need to be generated each time the same controller method is invoked.
It is very important to understand how the "Output Cache" works. Anyone who invokes a controller method will get the same cached version of the view page. This means that the amount of work that the web server must perform to serve the view page is dramatically reduced.
ASP.NET provides caching of web pages through Page Output Caching. A page is enabled for caching using the @OutputCache directive. This directive is written at the top of the page which is to be cached. The code below shows the code in the hold to cache a web page for 60 seconds.
Instead of using the @Outputcache directive, try doing it with code in the page. e.g.
void Page_Init() {
var outputCacheSettings = new OutputCacheParameters() {
Duration = 600,
VaryByCustom = VaryByCustomType.IsAuthenticated.ToString()
};
InitOutputCache(outputCacheSettings);
}
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