HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Configure in-memory cache limits

Describes how to configure in-memory cache limits.

Optimizely Content Management System (CMS) and Optimizely Customized Commerce use in-memory caching to optimize performance for frequently accessed data. A common example is Content that 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 application's memory usage goes above set thresholds, items are 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 free up the memory, the items must be garbage collected (provided nothing else than the cache holds references to them). This means there may be some delay from when 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. If the memory pressure remains high despite recent evictions, items are evicted more aggressively (a larger proportion of the total).


To use cache monitoring, the application startup has to call the AddCms (or AddCmsHost) extension method on IServiceCollection.

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

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 determines whether memory pressure should be monitored.
  • 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 exceeds the thresholds, a shorter interval may be automatically used to examine the current memory pressure closely.
  • int MaxMemoryPressurePercentage – The default value of int MaxMemoryPressurePercentage is 90. The application memory pressure (in percent), the amount of memory used by the process in relation to the estimated memory available, is considered the upper threshold. The application aims to keep memory pressure under this threshold by compacting the cache.

Configure the CacheMemoryMonitorOptions in appsettings.json as follows:

  "EPiServer": {
    "Cms": {
      "CacheMemoryMonitor": {
        "EnableMonitor": "true",
        "DefaultPollInterval": "0:0:20"
        "MaxMemoryPressurePrecentage": "85"