ny application you write may require some sort of caching to meet the performance requirements of the business. Until the release of Enterprise Library, developers were forced to roll out their own caching implementations; however, developers now finally have a standard out-of-the-box caching solution that is fully tested—and it's free! The Caching Application Block provides a flexible and extensible caching mechanism that can be used at any or all layers of an application. It supports in-memory, database, or isolated storage stores for persisting the cached data. It also includes a set of very easy-to-use APIs that let you incorporate standard caching operations into your applications without needing to learn the complexities of the caching implementation. This article introduces the Caching Application Block and shows examples of how to use it to write robust caching implementations.
The Caching Application Block
By default, the .NET Framework includes support for caching in web applications and web services through the classes contained in the System.Web.Cache namespace. However, not everyone's writing web applications; other application types can also sometimes benefit from caching to increase performance and availability. For example, if you are creating a smart client application that uses locally cached references to create requests and support offline operations, the built-in ASP.NET-based caching solution might not work. The same applies to a Windows service or console-based application in which you need to implement a local cache to improve performance.
|What You Need
|Visual Studio 2005 Professional RTM and Enterprise Library 3.1 May 2007
|Figure 1. Caching Application Block Dependencies: In addition to the core assemblies, the Caching Application Block references data access block and cryptography assemblies when required.|
The Caching Application Block solves such problems. After you install Enterprise Library 3.1 May 2007 edition, you can find the Caching Application Block assemblies in the <DriveName>:\Program Files\Microsoft Enterprise Library 3.1—May 2007\Bin
folder. To use the basic Caching Application Block features, you need to reference the Microsoft.Practices.EnterpriseLibrary.Common.dll
assemblies. By default, the Caching Application Block uses an in-memory backing store, but you can opt to use a SQL Server database as the backing store through the built-in SQL Server-based caching classes. To do that, you need to reference the Data Access Application Block as well. Figure 1
shows the Caching Application Block dependencies.
As Figure 1
shows, if you have the need to encrypt/decrypt cached data you must also reference the cryptography application block.