Find code clearing Sitecore caches

  • Description

    Sitecore Platform ships with multiple levels of caches in order to maximize the performance. The item fetch operation is backed by the following multiple caching layers by default:

    • ItemCache
    • DataCache
    • PrefetchCache

    The platform caching layer logic is located under the Sitecore.Caching namespace, while main cache-related logic is exposed by the Sitecore.Abstractions.BaseCacheManager contract or the static Sitecore.Caching.CacheManager class. The ClearAllCaches() API provided by the CacheManager leads to clearing all previously registered caches, likely causing a temporary performance drop. The corresponding log entry is written into Sitecore log files:

    WARN All caches have been cleared. This can decrease performance considerably.

    The Sitecore.Caching.ICacheInfo interface defines the Clear() API method that allows clearing caches on a more granular level as well.

    Sitecore Platform provides diagnostic capabilities to locate the cause for cache clearing.

  • To configure the cache cleanup mechanism to write diagnostic messages:

    1. Add the following setting into the Sitecore configuration:
      <setting name="Caching.DebugEnabled" value="true" />
    2. Configure Sitecore logger to write diagnostic messages:
      <root>
        <priority value="DEBUG" />
      </root>

    You can find the debug log entry with the cache cleanup call stack:

    6080 2018:07:04 16:08:22 DEBUG The 'web[blobIDs]' cache has been cleared.
    Entries removed: 0
    StackTrace:
       at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
       at System.Environment.get_StackTrace()
       at Sitecore.Caching.Generics.Cache`1.DoLogDebugMessage(String messagePrefix, String messageBody, Boolean ensureDebugEnabled) in
       at Sitecore.Caching.Generics.Cache`1.Clear()
       at Sitecore.sitecore.admin.CacheAdmin.ClearAllButtonClick(Object sender, EventArgs arguments)
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
    

    When the investigation is over, revert the configuration change.

Applies to:

CMS 8.2+

July 30, 2018
July 30, 2018