1

I've recently setup some caching for multiple websites that uses MemoryCache. The item I'm adding is a dataset and has an absolute expiry of 12 hours from the time it's added. What I want to know though, is there a way of clearing the cache manually, such as an IIS reset?

I couldn't find anything that categorically specified that memory cache would be cleared.

The reason behind this is that I need to test whether refreshed data in the database is picked up as expected if the cache is cleared. At the moment it doesn't seem to be clearing for all websites, which seems odd. So I need to figure out if this could be an issue with the app pools not restarting properly etc.

sr28
  • 4,728
  • 5
  • 36
  • 67
  • 1
    The answer here is *essentially* "yes, in-process/in-app-domain memory will be toast any time your app-pool ceases to exist / restarts" - that won't be explicit in the docs of `MemoryCache`, but is a logical consequence of the life-cycle of the process. Does your testing suggest otherwise? – Marc Gravell Oct 07 '16 at 15:26
  • Alternatively, you can develop a basic in-app or standalone functionality to clear the cache and expand on your testing – EGN Oct 07 '16 at 15:28
  • 2
    Some one answered for this question. http://stackoverflow.com/questions/15037050/caching-is-not-being-clear-on-site-restart – Ram Oct 07 '16 at 15:30
  • 1
    @MarcGravell - well, I don't think so. The initial thought was this might be the case as the 2 websites using this caching weren't consistent with each other. 1 showed new refreshed data after the reset, whilst the other didn't. My current theory is that the IIS reset didn't actually restart 1 of the app pools even though it said 'started' as after manually going to that app pool and stopping it, it wouldn't restart. Finally it did and the data then came through. – sr28 Oct 07 '16 at 15:34
  • Short answer No, restart the AppPool instead. – Eric Brown - Cal Jun 25 '18 at 21:30

1 Answers1

0

From my experiences and from peoples comments to back this up, it appears that it essentially does. The problem I was facing was actually an app pool not restarting properly, which lead to me thinking it hadn't cleared. It was actually an issue with the app pool.

sr28
  • 4,728
  • 5
  • 36
  • 67