Deleting Items from the Cache
There are several reasons for an item to be removed from an application's Cache. You can set expiration policies that determine the total amount of time the item remains in the cache (absolute expiration). You can also set expiration policies that are based on the amount of time that must pass following the previous time the item is accessed (sliding expiration). You can also specify files, directories, or keys that the item is dependent on. The item is removed from the Cache when those dependencies change. The server itself can remove an item from the Cache when it needs to free memory (scavenging). You have control over the priorities of cached items when this occurs. Any of these methods for removing items from the Cache are determined when you write code to add the item to the Cache using either the Cache.Add or Cache.Insert method. For more information, see Adding Items to the Cache.
Additionally, you can explicitly remove items from the Cache by using the Cache.Remove method. You can use this method in event-handler code to respond to user input or some other input from your application.
To delete an item from the Cache by using the Remove method
The Remove method has one parameter that allows you to specify the key of the item you want to remove. For example, the following code removes an item assigned the
MyData1
key.Cache.Remove("MyData1") [C#] Cache.Remove("MyData1");
See Also
Caching Application Data | Adding Items to the Cache | Retrieving Values of Cached Items | Notifying Applications When an Item Is Deleted from the Cache