0

In Asp.net Forms or MVC application, cache items which use System.Web.Caching get clear in an app pool restart. But what happens if caching was achieved using System.Runtime.Caching ?

CodingPanda
  • 178
  • 1
  • 14

1 Answers1

4

But what happens if caching was achieved using System.Runtime.Caching ?

If you are using the MemoryCache default implementation then exactly the same will happen because the items will be stored in memory of the AppDomain. If you want your cache items to survive application pool restarts you might need to use a distributed cache system such as Redis or Memcached. By using a distributed cache system all the nodes of your web cluster will have access to those cache items and might take advantage of them.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Thanks a lot !!! I thought System.runtime.cache keep it separate from appdomain. Is there way to share MemoryCache item between MVC app and **Windows** service application ? – CodingPanda Jan 30 '17 at 08:08
  • No, there's no way to share the MemoryCache between AppDomains. It is not designed for this purpose. You will need a distributed cache which can be shared. – Darin Dimitrov Jan 30 '17 at 08:08