Overview of Caching


ASP.NET provides two types of caching:

  • Output caching: This is the ability to cache an entire Web page or portions of a Web page if they are contained in user controls. ASP.NET can cache multiple versions of the same page if the requests vary by certain parameters. For example, ASP.NET will vary the cache by using a page's HTTP Response headers or by using its posted form parameters. You need to specify which Response headers, or form parameters, these are. Alternatively, you can choose to not vary the cache by any particular parameter. This results in every client request receiving the same cached version of the cached content.

  • Application data caching: This is the ability to cache individual objects and data in server memory. The Cache API provides this ability by offering programmatic access to the cache. The Page object's Cache property conveniently exposes the application programming interface (API). Application data caching allows very granular control over cached content. It provides an interesting range of expiration policies, including dependency-based expiration, which links cached content to specific data or to a specific file. This enables the cache to persist as long as its dependency remains unchanged.

Each type of caching works on a similar principle. Content gets added to the cache the first time that a user requests it. Subsequent users continue to receive a cached copy of the content until the cache expires . When this happens, the cache gets repopulated with content, and the cycle begins again. Caching saves the server from having to process the same request multiple times. This feature reduces processing costs, which in turn typically improves an application's performance, scalability, and responsiveness.

The two types of caching described may be founded on the same principle, but they behave differently. Output caching is reliable, and the content is guaranteed to persist (be present) in the cache until it expires. Application data caching is more flexible but is less reliable because content is not guaranteed to remain in the cache. This feature is by design and for efficiency purposes. The Cache API uses a process called scavenging to clear out cached content that is infrequently used. This process frees up server resources while impacting a relatively small percentage of clients . The overall application gains in terms of performance because the cache uses server resources in the most optimal way.

By definition, cached content is a copy of the original, which means that it can always be re-created. This point may seem obvious, but it has an interesting implication ”namely, that it is perfectly acceptable for cached content to expire and to be scavenged without your specific consent . This approach is much better than one that guarantees cache persistence above all else, even at the expense of efficiency and memory usage. Cached content can be re-created, often without the client even realizing it. But poor application performance and responsiveness is not so easy to hide. ASP.NET caching provides a range of options for satisfying different kinds of caching requirements.




Performance Tuning and Optimizing ASP. NET Applications
Performance Tuning and Optimizing ASP.NET Applications
ISBN: 1590590724
EAN: 2147483647
Year: 2005
Pages: 91

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