DbContextOptionsBuilder.UseMemoryCache(IMemoryCache) Method

Definition

Sets the IMemoryCache to be used for query caching by this context.

Note that changing the memory cache can cause EF to build a new internal service provider, which may cause issues with performance. Generally it is expected that no more than one or two different instances will be used for a given application.

This method cannot be used if the application is setting the internal service provider through a call to UseInternalServiceProvider(IServiceProvider). In this case, the IMemoryCache should be configured directly in that service provider.

public virtual Microsoft.EntityFrameworkCore.DbContextOptionsBuilder UseMemoryCache (Microsoft.Extensions.Caching.Memory.IMemoryCache memoryCache);
abstract member UseMemoryCache : Microsoft.Extensions.Caching.Memory.IMemoryCache -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
override this.UseMemoryCache : Microsoft.Extensions.Caching.Memory.IMemoryCache -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
Public Overridable Function UseMemoryCache (memoryCache As IMemoryCache) As DbContextOptionsBuilder

Parameters

memoryCache
IMemoryCache

The memory cache to be used.

Returns

DbContextOptionsBuilder

The same builder instance so that multiple calls can be chained.

Applies to