Partager via


Flushing the Cache

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.

public void FlushCache(ICacheManager cache)
{
  cache.Flush();
}
'Usage
Public Sub FlushCache(ByVal cache As ICacheManager)
  cache.Flush()
End Sub