A couple of weeks ago I had the requirement to enable ASP.NET output caching programmatically rather than declarative using the <%@ OutputCache ... %> tag.
I tried to follow the hints in the following KB: http://support.microsoft.com/default.aspx?id=323290. Actually what I found is that these procedure do not really work as expected.
Especially the following in which I was interested:
<%@ OutputCache Duration="60" Location="Server" VaryByParam="None" %>
What I found is that when using CTRL-F5 the declarative approach always returned the cached version but the programmatic approach returned a new version from the server. Not what I was looking for as I needed to control the amount of time but without affecting any other caching features.
Finally someone in the ASP.NET caching newsgroup was able to point me to the solution for this. There is an extra property that needs to be set to ensure that the cache gets persisted through CTRL-F5.
Here is now the complete code: