AspireRedisDistributedCacheExtensions.WithDistributedCache Method

Definition

Configures the Redis client to also provide distributed caching services through IDistributedCache.

public static Aspire.StackExchange.Redis.AspireRedisClientBuilder WithDistributedCache(this Aspire.StackExchange.Redis.AspireRedisClientBuilder builder, Action<Microsoft.Extensions.Caching.StackExchangeRedis.RedisCacheOptions>? configureOptions = default);
static member WithDistributedCache : Aspire.StackExchange.Redis.AspireRedisClientBuilder * Action<Microsoft.Extensions.Caching.StackExchangeRedis.RedisCacheOptions> -> Aspire.StackExchange.Redis.AspireRedisClientBuilder
<Extension()>
Public Function WithDistributedCache (builder As AspireRedisClientBuilder, Optional configureOptions As Action(Of RedisCacheOptions) = Nothing) As AspireRedisClientBuilder

Parameters

configureOptions
Action<RedisCacheOptions>

An optional method that can be used for customizing the RedisCacheOptions.

Returns

The AspireRedisClientBuilder for method chaining.

Examples

The following example creates an IDistributedCache service using the Redis client connection named "redis".

var builder = WebApplication.CreateBuilder(args);

builder.AddRedisClientBuilder("redis")
       .WithDistributedCache();

The created IDistributedCache service can then be resolved from an IServiceProvider:

IServiceProvider serviceProvider = builder.Services.BuildServiceProvider();

var cache = serviceProvider.GetRequiredService<IDistributedCache>();

Applies to