Chapter 12. Caching

Just about every website serves some amount of content that changes infrequently, be it static pages that only change with an application update, or content pages that change every few days or even every few hours.

The problem is, your web application is working hard to generate this content from scratch every time it’s requested, blissfully unaware that it has generated the same thing perhaps thousands of times already. Wouldn’t it make more sense to try to avoid generating the same content over and over again, choosing instead to generate and store the content once, then use that same content again in response to future requests?

The concept of storing and reusing generated data is called caching, and it’s one of the most effective ways to improve your web application’s performance. Which content should be cached, however—and how long to cache it for—is not typically something a web application can figure out by itself. Instead, you must provide your application with the information it needs in order to determine which content makes a good candidate for caching.

Luckily, both the core ASP.NET Framework and the ASP.NET MVC Framework provide a number of caching APIs to meet all of your caching needs. This chapter explores the various caching techniques and APIs that are available to you and how you can leverage these techniques to improve the performance of your ASP.NET MVC applications.

Types of Caching

Web application caching techniques generally fall into one of ...

Get Programming ASP.NET MVC 4 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.