Adding Application Code

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

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 adapt it as needed.

To prepare your application

  1. Add a reference to the Caching Application Block assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add References. 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.

  2. Use the same procedure to set a reference to the Enterprise Library Common assembly, named Microsoft.Practices.EnterpriseLibrary.Common.dll.

  3. Follow the same procedure to set a reference to the Enterprise Library Common assembly, Microsoft.Practices.EnterpriseLibrary.Common.dll and to the ObjectBuilder assembly, Microsoft.Practices.EnterpriseLibrary.ObjectBuilder2.dll.

  4. If you are using the database backing store, add a reference to Microsoft.Practices.EnterpriseLibrary.Caching.Database.dll and Microsoft.Practices.EnterpriseLibrary.Data.dll.

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

  6. (Optional) To use elements from the Caching Application Block without fully qualifying the element reference, add the following using statements (C#) or Imports statements (Visual Basic) to the top of your source code file.

    using Microsoft.Practices.EnterpriseLibrary.Caching;
    using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;
    
    'Usage
    Imports Microsoft.Practices.EnterpriseLibrary.Caching
    Imports Microsoft.Practices.EnterpriseLibrary.Caching.Expirations
    

Note

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 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:

  1. Create the CacheManager object.
  2. Call the appropriate method.

Each key scenario demonstrates how to incorporate these steps into an application.