Walkthrough: Adding Items to the Cache

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.

This walkthrough demonstrates how to add items to the cache.

To reproduce the demonstration

  1. Configure the cache. For the necessary steps, see Configuring Enterprise Library.
  2. Declare a member variable of type ICacheManager to store the CacheManager object in the QuickStartForm class.
  3. In the QuickStartForm_Load method (when not using the Unity Integration approach), create the CacheManager by adding the following code. The call to GetCacheManager does not include the name of a CacheManager so the factory creates the default CacheManager object, as indicated in the configuration file.
  4. Create the item that will be added to the cache. The following code creates an item of type Product.
  5. Add the item to the cache. The following code uses the overload of the Add method that includes the scavenging priority (in this case, Normal), does not specify a callback handler, and sets an expiration time of 5 minutes from the time the item was last accessed.