I have created a cache using the MemoryCache class. I add some items to it but when I need to reload the cache I want to clear it first. What is the quickest way to do this? Should I loop through all the items and remove them one at a time or is there a better way?
MemoryCache is a service so you can't dispose the cache. Simply remove the cached items you wish to remove. If you want to clear every item in cache then loop over the key and remove each item.
The cache should be cleared regularly for several reasons. Depending on your settings, the cache can grow quite big and use a lot of disk space on your computer. And that's even if you don't visit some pages ever again. The more information that is saved in the cache, the slower your computer will be browsing the web.
Dispose
the existing MemoryCache and create a new MemoryCache object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With