Share via


DbContextOptionsBuilder.UseMemoryCache(IMemoryCache) Method

Definition

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

public virtual Microsoft.EntityFrameworkCore.DbContextOptionsBuilder UseMemoryCache (Microsoft.Extensions.Caching.Memory.IMemoryCache memoryCache);
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

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

Remarks

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.

See Using DbContextOptions and Caching in .NET for more information.

Applies to