MemoryCacheElement.CacheMemoryLimitMegabytes Property

.NET Framework (current version)

Gets or sets the maximum memory size, in megabytes, that an instance of a MemoryCache object can grow to.

Namespace:   System.Runtime.Caching.Configuration
Assembly:  System.Runtime.Caching (in System.Runtime.Caching.dll)

	DefaultValue = 0)]
[IntegerValidatorAttribute(MinValue = 0)]
public int CacheMemoryLimitMegabytes { get; set; }

Property Value

Type: System.Int32

The amount of maximum memory size, in megabytes. The default is zero, which indicates that MemoryCache instances manage their own memory based on the amount of memory that is installed on the computer.

The CacheMemoryLimitMegabytes property value represents the cacheMemoryLimitMegabytes configuration attribute in the namedCaches configuration element.

If the cache size exceeds the specified limit, the memory cache implementation removes cache entries.

This property can be set individually in namedCaches elements, with each namedCaches element corresponding to a unique cache configuration.

The settings for the CacheMemoryLimit property can be read from the cacheMemoryLimitMegabytes configuration attribute in the configuration file. Alternatively, the settings can be passed when the MemoryCache class is initialized.

For more information about how to configure the cache, see <namedCaches> Element (Cache Settings).

.NET Framework
Available since 4.0
Return to top