Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

DbContextOptionsBuilder.UseMemoryCache(IMemoryCache) Method

Definition

Namespace:
Microsoft.EntityFrameworkCore
Assembly:
Microsoft.EntityFrameworkCore.dll
Package:
Microsoft.EntityFrameworkCore v1.0.6
Package:
Microsoft.EntityFrameworkCore v1.1.6
Package:
Microsoft.EntityFrameworkCore v10.0.0
Package:
Microsoft.EntityFrameworkCore v2.0.3
Package:
Microsoft.EntityFrameworkCore v2.1.11
Package:
Microsoft.EntityFrameworkCore v2.2.6
Package:
Microsoft.EntityFrameworkCore v3.0.0
Package:
Microsoft.EntityFrameworkCore v3.1.0
Package:
Microsoft.EntityFrameworkCore v5.0.0
Package:
Microsoft.EntityFrameworkCore v6.0.0
Package:
Microsoft.EntityFrameworkCore v7.0.0
Package:
Microsoft.EntityFrameworkCore v8.0.0
Package:
Microsoft.EntityFrameworkCore v9.0.0
Source:
DbContextOptionsBuilder.cs
Source:
DbContextOptionsBuilder.cs
Source:
DbContextOptionsBuilder.cs
Source:
DbContextOptionsBuilder.cs
Source:
DbContextOptionsBuilder.cs
Source:
DbContextOptionsBuilder.cs
Source:
DbContextOptionsBuilder.cs
Source:
DbContextOptionsBuilder.cs
Source:
DbContextOptionsBuilder.cs
Source:
DbContextOptionsBuilder.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

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


Feedback

Was this page helpful?