Varying the Output Cache by a Custom Function
The VaryByCustom
attribute is named the VaryByCustom
attribute for a reason. You can specify a custom function that determines when a different cached version of a page is generated.
You can use any criteria that you want with the custom function. You can create different cached versions of a page depending on the browser minor version, the browser DOM support, the time of day, or even the weather.
You create the custom function in the Global.asax
file by overriding the GetVaryByCustomString()
method. For example, the Global.asax
file in Listing 29.7 illustrates how you can override the GetVaryByCustomString()
method to create different cached versions of a page depending on a particular feature ...
Get ASP.NET 4 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.