|Microsoft Enterprise Library 5.0|
|Adding Application Code|
The Caching Application Block is designed to support the most common situations for storing data in a cache. When adding your application code, refer to the scenarios in the Key Scenarios sections and select the ones that best suit your situation. Use the code that accompanies the scenario either as it is, or revise it as required.
To prepare your application
- Add a reference to the Caching Application Block assembly. In Microsoft Visual Studio®, right-click your project node in Solution Explorer, and then click Add Reference. Click the Browse tab and find the location of the Microsoft.Practices.EnterpriseLibrary.Caching.dll assembly. Select the assembly, and then click OK to add the reference.
- Follow the same procedure to set a reference to the following assemblies:
- If you are using the database backing store, add a reference to Microsoft.Practices.EnterpriseLibrary.Caching.Database.dll and Microsoft.Practices.EnterpriseLibrary.Data.dll.
- If you are using the Cryptography Application Block to encrypt data in the cache, add references to Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll and Microsoft.Practices.EnterpriseLibrary.Caching.Cryptography.dll.
- (Optional) To use elements from the Caching Application Block without fully qualifying the element reference, add the following using statements (C#) or Imports statements (Microsoft Visual Basic®) to the top of your source code file.
C# Copy Code
using Microsoft.Practices.EnterpriseLibrary.Caching; using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;
Visual Basic Copy Code
Imports Microsoft.Practices.EnterpriseLibrary.Caching Imports Microsoft.Practices.EnterpriseLibrary.Caching.Expirations
|For Visual Basic projects, you can also use the References page of the Project Designer to manage references and imported namespaces. To access the References page, select a project node in Solution Explorer, and then click [project name] Properties on the Project menu. When the Project Designer appears, click the References tab.|
Next, add the application code. Generally, there are two steps to create code that uses the Caching Application Block:
- Resolve a CacheManager instance.
- Call the appropriate methods.
Each key scenario demonstrates how to incorporate these steps into an application.