How do I clear a System.Runtime.Caching.MemoryCache

后端 未结 7 2304
隐瞒了意图╮
隐瞒了意图╮ 2020-12-09 07:16

I use a System.Runtime.Caching.MemoryCache to hold items which never expire. However, at times I need the ability to clear the entire cache. How do I do that?

7条回答
  •  悲哀的现实
    2020-12-09 08:09

    Check out this post, and specifically, the answer that Thomas F. Abraham posted. It has a solution that enables you to clear the entire cache or a named subset.

    The key thing here is:

    // Cache objects are obligated to remove entry upon change notification.
    base.OnChanged(null);
    

    I've implemented this myself, and everything seems to work just fine.

提交回复
热议问题