Chapter 12. Data caching
This chapter covers
- System.Runtime.Caching
- What should I cache?
- Notes on distributed caching
In the same way that you might keep milk in your fridge until it reaches its expiration date, as I said in chapter 4, browsers can cache information about a website for a set duration of time. When your milk is old, you buy new. After data expires, a browser will fetch the updated version. Much like caching data on a user’s browser with HTTP caching, as discussed in chapter 4, you can do the same thing with frequently used information on the server. By caching data on the server, you can easily store information retrieved from the database, or perhaps even an expensive method.
Data caching is the process of storing frequently used data on the server to fulfill subsequent requests. If some data doesn’t change often, store it on the server so you don’t have to make an expensive call to the database the next time you request it.
Data caching is one of my favorite server-side techniques for speeding up an application and making it more robust. The .NET Framework has great built-in support for data caching and it can be applied to a web application in no time at all. This chapter runs through setting up data caching in a web application and shows how easy it is to use this great feature.