AspireRedisDistributedCacheExtensions.WithDistributedCache Method
Definition
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.
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
- builder
- AspireRedisClientBuilder
The AspireRedisClientBuilder to configure.
- 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>();