views:

71

answers:

1

Is it possible to detect whether an ASP.NET Page is about to be cached and if so, how?

The HttpCachePolicy object provides only set-methods. The VaryByParams name-value collection is useless if values other than "None" and "*" are set as it impossible to enumerate them and you can only access them by key.

Additionally, I cannot use Reflection.

Any ideas?

+1  A: 

One approach which might work if you're using ASP.NET 4.0 would be to implement your own custom OutputCacheProvider. You could then add your detection logic inside the provider.

See the MSDN ASP.NET Caching Overview for examples of adding the provider to your web.config and using the providerName attribute in your @Page or @Control directive.

David Gardiner
Thank you for your response. Unfortunately I need a 2.0+ solution. My current research shows no way of doing this - ASP.NET effectively shuts every door to the 'private' Cache (where it actually caches things) and one cannot even read a single property giving away any information about the Cache or whether the Page is about to get cached or not.
simz