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.

Data stored in the cache must be retrieved so that it can be displayed or processed. For example, in a retail application, you may want to display a list of products from a catalog.

Typical Goals

In this scenario, you want to retrieve a particular item from the cache.

Solution

Use the GetData method provided by the CacheManager class; it returns the value associated with a specific key.

QuickStart

For an extended example of how to use the GetData method, see the QuickStart walkthrough, Walkthrough: Retrieving Items From the Cache.

Using the GetData Method

The following code shows how to use the GetData method. Add the code to the method responding to the request to retrieve an item from the cache.

// Read the item from the cache. If the item is not found
// in the cache, the return value will be null.
public Product GetProduct(CacheManager cache, string key)
{
  return (Product)cache.GetData(key);
}
' Read the item from the cache. If the item is not found
' in the cache, the return value will be null.
Public Function GetProduct(ByVal cache As CacheManager, ByVal key As String) As Product
Return DirectCast(Cache.GetData(key), Product)
End Function
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.