Chapter 18. Caching and Performance

There are several ways to achieve higher performance and better scalability in ASP.NET. One way is through the use of caching. Caching is a technique whereby frequently requested data is stored in a quickly accessible location, so that the next time the same data is requested, it can be quickly fetched from the cache location rather than regenerated by the application.

This can result in a significant performance boost, especially for dynamically generated content (such as ASP.NET web pages and components), and in cases where the data underlying the response is expensive to gather (such as database queries).

Most web browsers cache pages received so that if the same page is requested again, it does not have to be sent over the Internet, but rather is retrieved directly from the local hard drive. Most operating systems also employ caching of some sort to store frequently requested data in memory, rather than require additional hard drive reads.

The only caching this chapter will be concerned with is server-side caching performed by the .NET Framework.

In some respects, caching is similar to the storage of state objects. (See Chapter 6 for a complete discussion of state in ASP.NET.) In both cases, data is saved for use across multiple requests, and, in the case of application state, across multiple sessions. However, there the similarity ends. With state objects, the developer explicitly saves a particular piece of data in a particular place, intending ...

Get Programming ASP.NET, Second Edition 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.