Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Loading...
Area: Optimizely CMS
Applies to versions: 12 and higher

Configure in-memory cache limits

Recommended reading 
Note: This documentation is for the preview version of the upcoming release of CMS 12/Commerce 14/Search & Navigation 14. Features included here might not be complete, and might be changed before becoming available in the public release. This documentation is provided for evaluation purposes only.

Overview

Optimizely CMS and Commerce utilize in-memory caching to optimize performance for frequently accessed data. A common example is Content which is cached automatically by the platform, but many other entities in the platform are cached as well and you can also cache custom data by using the ISynchronizedObjectInstanceCache interface.

The cache growth is limited by continuously monitoring the memory usage. When the memory usage of the application goes above set thresholds, items will be evicted from the cache. The platform will remove items in the following order to attempt to bring the memory below the threshold levels:

  • All expired items.
  • Items by priority. Lowest priority items are removed first.
  • Least recently used objects.
  • Items with the earliest absolute expiration.
  • Items with the earliest sliding expiration.

To actually free up the memory, the items also have to be garbage collected (provided nothing else than the cache holds references to them). This means there may be some delay from the time items are evicted from the cache until the memory is recovered.

The eviction process is costly so the platform will only perform it at certain intervals. However, when the memory pressure is high, the interval is shortened, and if the memory pressure remains high despite recent evictions, items will be evicted more aggressively (larger proportion of the total).

Configuration

To use cache monitoring, the application startup has to call the AddCmsHost extensions method on IServiceCollection.

To tune the memory monitor, you can use the options in the EPiServer.Framework.Cache.CacheMemoryMonitorOptions options class.

CacheMemoryMonitorOptions

The CacheMemoryMonitorOptions controls the thresholds and timing used when monitoring the cache memory usage.

  • Bool EnableMonitor. The default value of bool EnableMonitor is true and it determines if the memory pressure should be monitored or not.
  • TimeSpan DefaultPollInterval. The default value of TimeSpan DefaultPollInterval  is 30 sec and sets the default interval between checks of the memory pressure and potential compacting of the cache, if high memory pressure is detected. The default interval is used when the load is below thresholds. When the pressure goes above the thresholds, a shorter interval may be automatically used to keep a closer look on the current memory pressure.
  • int MaxMemoryPressurePercentage. The default value of int MaxMemoryPressurePercentage is 90. The application memory pressure (in percent), that is, the amount of memory used by the process in relation to the estimated memory available, that is considered the upper threshold. The application aims to keep memory pressure under this threshold by compacting the cache.

The CacheMemoryMonitorOptions can be configured in appsettings.json like:

{
   "EPiServer":{
      "Cms":{
        "CacheMemoryMonitor":{
            "EnableMonitor": "true",
            "DefaultPollInterval":"0:0:20"
            "MaxMemoryPressurePrecentage": "85"
         }      
     }
   }
}
Do you find this information helpful? Please log in to provide feedback.

Last updated: Jul 02, 2021

Recommended reading