Section 17.1. Types of Caching

17.1. 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.

17.1.1. 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 the assembly the next time the page or service is called.

17.1.2. Configuration Caching

Application-wide configuration information is contained in the configuration files. Chapter 18 discusses the specifics of configuration in detail. For now, the relevant point is that when the application is started (the first time a page or service is called from the application virtual root directory), all the configuration information must be loaded. This can take some time, especially if the configuration files are extensive . Configuration caching, which occurs automatically, allows the application to store the configuration information in memory, thus saving time when the information is subsequently needed.

17.1.3. Data Caching

Caching data from a database is one of the most effective ways to improve performance and scalability of a web application, since database hits are a relatively expensive operation, especially when compared with retrieving the data from server memory. The DataSource controls, new to ASP.NET Version 2.0 and covered in detail in Chapter 9, are specifically designed to enable easy and effective caching of data . Data caching will be covered in the next section of this chapter.

17.1.4. Output Caching

Output caching is the caching of pages or portions of pages that are sent to the client. This is one of the most significant performance-enhancing techniques available to the web-site developer. Since the page does not have to be recreated from scratch each time a request for it is made, the web site throughput, for example, measured in requests fulfilled per second, can be significantly increased.

Output caching is discussed later in this chapter.

17.1.5. Object Caching

Object caching is the caching of objects on the page, such as data bound controls. Object caching stores the cached data in server memory. Object caching will be covered in detail later in the chapter.



Programming ASP. NET
Programming ASP.NET 3.5
ISBN: 0596529562
EAN: 2147483647
Year: 2003
Pages: 173

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net