Using the HttpCachePolicy Class to Enable Output Caching

As previously mentioned, the @OutputCache directive is derived from the HttpCachePolicy class, which gives you lower-level access to the output cache. The HttpCachePolicy class is exposed through the HttpResponse.Cache property; and it is a member of the System.Web namespace. You would want to use the HttpCachePolicy rather than the @OutputCache when you need to dynamically set the output cache settings. For instance, if you want to dynamically set how long the item should remain in the cache.

The @OutputCache directive exposes nearly all the functionality available from using the HttpCachePolicy class, but the class does offer more functionality than @OutputCache. For instance, when using ...

Get Programming Data-Driven Web Applications with ASP.NET 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.