MemoryCacheServiceCollectionExtensions.AddMemoryCache Method

Definition

Overloads

AddMemoryCache(IServiceCollection)

Adds a non distributed in-memory implementation of IMemoryCache to the IServiceCollection.

AddMemoryCache(IServiceCollection, Action<MemoryCacheOptions>)

Adds a non distributed in-memory implementation of IMemoryCache to the IServiceCollection.

AddMemoryCache(IServiceCollection)

Source:
MemoryCacheServiceCollectionExtensions.cs
Source:
MemoryCacheServiceCollectionExtensions.cs
Source:
MemoryCacheServiceCollectionExtensions.cs

Adds a non distributed in-memory implementation of IMemoryCache to the IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddMemoryCache(this Microsoft.Extensions.DependencyInjection.IServiceCollection services);

Parameters

services
IServiceCollection

The IServiceCollection to add services to.

Returns

The IServiceCollection so that additional calls can be chained.

Applies to

.NET 10 (package-provided) и други версии
Продукт Версии
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

AddMemoryCache(IServiceCollection, Action<MemoryCacheOptions>)

Source:
MemoryCacheServiceCollectionExtensions.cs
Source:
MemoryCacheServiceCollectionExtensions.cs
Source:
MemoryCacheServiceCollectionExtensions.cs

Adds a non distributed in-memory implementation of IMemoryCache to the IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddMemoryCache(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action<Microsoft.Extensions.Caching.Memory.MemoryCacheOptions> setupAction);

Parameters

services
IServiceCollection

The IServiceCollection to add services to.

setupAction
Action<MemoryCacheOptions>

The Action<T> to configure the provided MemoryCacheOptions.

Returns

The IServiceCollection so that additional calls can be chained.

Applies to

.NET 10 (package-provided) и други версии
Продукт Версии
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)