Types of Caching

There are several different types of caching in ASP.NET. Some are automatic and require no intervention on the developer’s part, whereas others require explicit coding.

In all types of caching, data or objects are placed in the cache, an area of memory managed by the server. Subsequent requests for that information are retrieved from the cache rather than the underlying source. If the cached item has expired, either because the underlying data has changed, the time limit has run out, or some dependency has changed, the cache will be invalidated and the next request will retrieve fresh content from the underlying source rather than the cache. Your code can then refresh the cache. There are many ways to add items to the cache and expire items already in the cache, depending on the type of cache. We cover the types of cache in the next few sections, and the many ways of populating and expiring the cache in subsequent sections.

Class Caching

A web page or web service (.aspx, .asmx, or .svc file) is compiled into a page class in an assembly the first time the page or service is run. This causes some delay, but that compiled assembly is then cached on the server and is called directly every subsequent time the page (or service) is referenced. This is done automatically; no user or developer interaction is required for this to happen.

The CLR watches for source code changes. If the source code changes, the CLR will know to recompile the assembly the next time the page or service ...

Get Programming ASP.NET 3.5, 4th 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.