Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear MemoryCache?

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?

like image 265
Retrocoder Avatar asked Nov 15 '10 10:11

Retrocoder


People also ask

How do I reset my MemoryCache?

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.

Should I clear cached memory?

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.


1 Answers

Dispose the existing MemoryCache and create a new MemoryCache object.

like image 191
GvS Avatar answered Sep 29 '22 12:09

GvS