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 CMS caches automatically, but the platform caches many other entities as well. Cache custom data using the ISynchronizedObjectInstanceCache interface.
The platform limits cache growth by continuously monitoring memory usage. When the application's memory usage exceeds set thresholds, items are evicted from the cache in the following order:
- 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 memory, the items must be garbage collected (provided nothing other than the cache holds references to them). There is some delay from when items are evicted from the cache until the memory is recovered.
The eviction process is costly, so the platform only performs it at certain intervals. When 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).
CacheMemoryMonitorOptions
Use CacheMemoryMonitorOptions to tune the memory monitoring thresholds and timing for cache eviction.
To use cache monitoring, the application startup must call the AddCms (or AddCmsHost) extension method on IServiceCollection.
Tune the memory monitor using the options in the EPiServer.Framework.Cache.CacheMemoryMonitorOptions class.
bool EnableMonitor– Determines whether to monitor memory pressure. Default: true.TimeSpan DefaultPollInterval– Sets the default interval between memory pressure checks and potential cache compaction. The default interval is used when the load is below thresholds. When the pressure exceeds the thresholds, a shorter interval is used automatically. Default: 30 sec.int MaxMemoryPressurePercentage– The application memory pressure (in percent): the amount of memory used by the process in relation to the estimated memory available. The application aims to keep memory pressure under this threshold by compacting the cache. Default: 90.
Configure CacheMemoryMonitorOptions in appsettings.json as follows:
{
"EPiServer": {
"Cms": {
"CacheMemoryMonitor": {
"EnableMonitor": "true",
"DefaultPollInterval": "0:0:20",
"MaxMemoryPressurePercentage": "85"
}
}
}
}Updated 19 days ago
