EPiWiki.se  - EPiServer notes shared with others
 

Disable clear cache

[Edit]
For high performance sites it can be catastrophic to clear all pages in the cache, here is a sample code to disable that functionality.

EPiServer CMS 6 and above



CacheManager.ClearCacheOnLoadBalanceEventMissed = false;

EPiServer CMS 5



Event e = Event.Get(CacheManager.RemoveFromCacheEventId);
FieldInfo infoMissed = e.GetType().GetField(
   "Missed",
   BindingFlags.NonPublic | BindingFlags.Instance);
EventHandler handler = (EventHandler)infoMissed.GetValue(e);
MethodInfo removeMethod = typeof(CacheManager).GetMethod(
   "RemoveFromCacheEvent_Missed", BindingFlags.Static | BindingFlags.NonPublic);
if (removeMethod == null)
{
   throw new ApplicationException(
      "Can't find method for EPiServer to clean the cache, EPiServer probebly upgraded");
}
 
foreach (EventHandler h in handler.GetInvocationList())
{
   if (h.Method == removeMethod)
   {
      e.Missed -= h;
   }
}
Version author:
Mattias Lövström

EPiServer version

'EPiServer CMS 5'