Data caching
Data caching is aimed at caching individual objects using code in your code behind, rather than caching pages or user controls via page directives. It lets you store key-value pairs in cache on the server. These pairs are then accessible for all requests to the same website. However, as you saw in the section about output caching, if you have a web farm with multiple servers, each server has access only to its own cache. It is very flexible you can specify expiry times, priorities, and dependencies on other items such as files or database objects.
We'll discuss more advanced topics such as database dependencies in a moment; first, let's see how to introduce data caching in your code.
Basic use
As you saw, you access the cache as a dictionary. The simplest way to add something to the cache is to assign an object to a key name:
Cache["key"] = myObject;
Retrieving an item goes along the same lines:
MyObject myObject = (MyObject)Cache[ key ];
The cache stores items as objects. So...