Types of Caching

There are several different types of caching in ASP.NET. Some are automatic and require no intervention on the part of the developer, while 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, then 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. The types of cache are covered in the next few sections, and the many ways of populating and expiring the cache will be covered in subsequent sections.

Class Caching

A web page or web service (.aspx or .asmx file, respectively) 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; there is no user or developer interaction required for this to happen.

The CLR watches for source code changes. If the source code changes, the CLR will know to recompile ...

Get Programming ASP.NET, 3rd 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.