asp.netasp.net-mvccachingiisasp.net-caching

System.Web.Caching & System.Runtime.Caching against IIS App Pool restarts


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 ?


Solution

  • 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.