Walkthrough: Retrieving Items From 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 retrieve items from the cache.

To reproduce this demonstration

  1. Configure the cache. For the necessary steps, see "QuickStart Configuration" in Caching QuickStart.
  2. Declare a member variable for the CacheManager object in the QuickStartForm class.
    private CacheManager primitivesCache;
    
    
    Private primitivesCache As CacheManager
    
    
  3. In the method that responds to the user's request to read an item from the cache, add the following code.
    // Prompt the user for the key of the item to be read.
    if (this.selectItemForm.ShowDialog() == DialogResult.OK)
    {
      // Read the item from the cache. If the item is not found in the cache, the
      // return value will be null.
      Product product = (Product) this.primitivesCache.GetData(selectItemForm.ItemKey);
    }
    
    
    
    ' Prompt the user for the key of the item to be read.
    If (Me.selectItemForm.ShowDialog() = DialogResult.OK) Then
      ' Read the item from the cache. If the item is not found in the cache, the
      ' return value will be null.
      Dim requestedProduct As Product = DirectCast(Me.primitivesCache.GetData(selectItemForm.ItemKey), Product)
    End If
    
    
    

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