# AspireRedisOutputCacheExtensions Methods

- Package: [Aspire.StackExchange.Redis.OutputCaching](/reference/api/csharp/aspire.stackexchange.redis.outputcaching.md)
- Type: [AspireRedisOutputCacheExtensions](/reference/api/csharp/aspire.stackexchange.redis.outputcaching/aspireredisoutputcacheextensions.md)
- Kind: `Methods`
- Members: `3`

Provides extension methods for adding Redis output caching services to the `Hosting.IHostApplicationBuilder`.

## AddKeyedRedisOutputCache(IHostApplicationBuilder, string, Action<StackExchangeRedisSettings>, Action<ConfigurationOptions>)

- Name: `AddKeyedRedisOutputCache(IHostApplicationBuilder, string, Action<StackExchangeRedisSettings>, Action<ConfigurationOptions>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Components/Aspire.StackExchange.Redis.OutputCaching/AspireRedisOutputCacheExtensions.cs#L66-L75)

Adds Redis output caching services for the given `name` in the services provided by the `builder`.

```csharp
public static class AspireRedisOutputCacheExtensions
{
    public static void AddKeyedRedisOutputCache(
        this IHostApplicationBuilder builder,
        string name,
        Action<StackExchangeRedisSettings>? configureSettings = null,
        Action<ConfigurationOptions>? configureOptions = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `name` (`string`)
  The name of the component, which is used as the `ServiceDescriptor.ServiceKey` of the service and also to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<StackExchangeRedisSettings>`) `optional`
  An optional method that can be used for customizing the `Redis.StackExchangeRedisSettings`. It's invoked after the settings are read from the configuration.
- `configureOptions` (`Action<ConfigurationOptions>`) `optional`
  An optional method that can be used for customizing the `Redis.ConfigurationOptions`. It's invoked after the options are read from the configuration.

## Remarks

Reads the configuration from "Aspire:StackExchange:Redis:{name}" section. Also registers `Redis.IConnectionMultiplexer` as a singleton in the services provided by the `builder`. Enables retries, corresponding health check, logging, and telemetry.

## AddRedisOutputCache(IHostApplicationBuilder, string, Action<StackExchangeRedisSettings>, Action<ConfigurationOptions>)

- Name: `AddRedisOutputCache(IHostApplicationBuilder, string, Action<StackExchangeRedisSettings>, Action<ConfigurationOptions>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Components/Aspire.StackExchange.Redis.OutputCaching/AspireRedisOutputCacheExtensions.cs#L36-L45)

Adds Redis output caching services in the services provided by the `builder`.

```csharp
public static class AspireRedisOutputCacheExtensions
{
    public static void AddRedisOutputCache(
        this IHostApplicationBuilder builder,
        string connectionName,
        Action<StackExchangeRedisSettings>? configureSettings = null,
        Action<ConfigurationOptions>? configureOptions = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `connectionName` (`string`)
  A name used to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<StackExchangeRedisSettings>`) `optional`
  An optional method that can be used for customizing the `Redis.StackExchangeRedisSettings`. It's invoked after the settings are read from the configuration.
- `configureOptions` (`Action<ConfigurationOptions>`) `optional`
  An optional method that can be used for customizing the `Redis.ConfigurationOptions`. It's invoked after the options are read from the configuration.

## Remarks

Reads the configuration from "Aspire:StackExchange:Redis" section. Also registers `Redis.IConnectionMultiplexer` as a singleton in the services provided by the `builder`. Enables retries, corresponding health check, logging, and telemetry.

## WithOutputCache(AspireRedisClientBuilder)

- Name: `WithOutputCache(AspireRedisClientBuilder)`
- Modifiers: `extension`
- Returns: `AspireRedisClientBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Components/Aspire.StackExchange.Redis.OutputCaching/AspireRedisOutputCacheExtensions.cs#L84-L99)

Configures the Redis client to provide output caching services through `OutputCaching.IOutputCacheStore`.

```csharp
public static class AspireRedisOutputCacheExtensions
{
    public static AspireRedisClientBuilder WithOutputCache(
        this AspireRedisClientBuilder builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`AspireRedisClientBuilder`)
  The `Redis.AspireRedisClientBuilder` to configure.

## Returns

`AspireRedisClientBuilder` -- The `Redis.AspireRedisClientBuilder` for method chaining.
