MemoryCache.CacheMemoryLimit Property

.NET Framework (current version)

Gets the amount of memory on the computer, in bytes, that can be used by the cache.

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

public long CacheMemoryLimit { get; }

Property Value

Type: System.Int64

The amount of memory in bytes.

If the current instance of the cache exceeds the limit on memory set by the CacheMemoryLimit property, the cache implementation removes cache entries. Each cache instance in the application can use the amount of memory that is specified by the CacheMemoryLimit property.

The settings for the CacheMemoryLimit property can be specified in the application configuration file. Alternatively, they can be passed in the constructor when the MemoryCache class is initialized. For more information about how to configure this property, see <namedCaches> Element (Cache Settings). For more information about how to set this value when the MemoryCache class is being initialized, see the MemoryCache method.

MemoryCache does not instantly enforce CacheMemoryLimit each time a new item is added to a MemoryCache instance. The internal heuristics which evicts extra items from the MemoryCache does it gradually and takes into account information from the garbage collector (see Garbage Collection) and other factors such as current cache size and overall system memory pressure. Therefore even though the MemoryCache tries to keep the cache size within the configured CacheMemoryLimit it is possible to temporarily exceed the limit by adding cache items at a very high rate.

.NET Framework
Available since 4.0
Return to top