Flushing the Cache

Microsoft Enterprise Library 5.0

DropDown image DropDownHover image Collapse image Expand image CollapseAll image ExpandAll image Copy image CopyHover image

Flushing lets you manage cached items to make sure that storage, memory, and other resources are used efficiently. Flushing removes all items in the cache, including those that have not yet expired. For example, in a retail application, cached data may no longer be valid because of selections made by the customer or because the customer has logged off.

Typical Goals

In this scenario, you want to remove all items from cache.

Solution

Use the Flush method provided by the CacheManager class. The Flush method removes all items from the cache. If an error occurs, the cache does not change.

Using the Flush Method

The following code shows how to use the Flush method. Add the code to the method that responds to the request to flush the cache.

C# Copy Code
public void FlushCache(ICacheManager cache)
{
  cache.Flush();
}
Visual Basic Copy Code
Public Sub FlushCache(ByVal cache As ICacheManager)
  cache.Flush()
End Sub