Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

How to: Delete Items from the Cache in ASP.NET

Data in the ASP.NET cache is volatile — that is, it is not permanently stored. It might be automatically removed from the cache for one of these reasons:

  • Because the cache is full.

  • Because the item has expired.

  • Because an item it is dependent on changes.

For more information see ASP.NET Caching Overview.

The specific method for removing items from the cache is determined in the code used to add the item to the cache. For more information, see How to: Add Items to the Cache. You can be notified when an item is removed from the cache. For more information see How to: Notify an Application When an Item Is Removed from the Cache.

In addition to allowing items to be removed from the cache automatically, you can explicitly remove them.

Note Note

If you call the Insert method and add an item to the cache with the same name as an existing item, the old item will be deleted from the cache.

To delete an item from the cache explicitly

  • Call the Remove method, passing the key of the item you want to remove.

    The following example shows how to remove an item with the key MyData1.

© 2015 Microsoft