Skip to main content
net10.0net8.0net9.0

A Redis® implementation for ASP.NET Core Output Caching that integrates with Aspire, including health checks, logging, and telemetry.

Published
Oct 24, 2026
9d ago
Total Downloads
1.1M
1,138,709

Install

dotnet add package Aspire.StackExchange.Redis.OutputCaching --version 13.6.4
ProductVersions
.NET
net10.0net8.0net9.0

README

Aspire.StackExchange.Redis.OutputCaching library

Registers an ASP.NET Core Output Caching provider backed by a Redis®* server. Enables corresponding health check, logging, and telemetry.

Getting started

Prerequisites

  • Redis server and the server hostname for connecting a client.

Install the package

Install the Aspire StackExchange Redis OutputCache library with NuGet:

dotnet add package Aspire.StackExchange.Redis.OutputCaching

Usage example

In the AppHost.cs file of your project, call the AddRedisOutputCache extension method to register the Redis output cache provider in the dependency injection container. The method takes a connection name parameter.

builder.AddRedisOutputCache("cache");

After the WebApplication has been built, add the middleware to the request processing pipeline by calling UseOutputCache.

app.UseOutputCache();

For minimal API apps, configure an endpoint to do caching by calling CacheOutput, or by applying the [OutputCache] attribute, as shown in the following examples:

app.MapGet("/cached", Gravatar.WriteGravatar).CacheOutput();
app.MapGet("/attribute", [OutputCache] (context) =>
    Gravatar.WriteGravatar(context));

For apps with controllers, apply the [OutputCache] attribute to the action method. For Razor Pages apps, apply the attribute to the Razor page class.

Configuration

The Aspire StackExchange Redis OutputCache component provides multiple options to configure the Redis connection based on the requirements and conventions of your project. Note that at least one host name is required to connect.

Use a connection string

When using a connection string from the ConnectionStrings configuration section, you can provide the name of the connection string when calling builder.AddRedisOutputCache():

builder.AddRedisOutputCache("myRedisConnectionName");

And then the connection string will be retrieved from the ConnectionStrings configuration section:

{
  "ConnectionStrings": {
    "myRedisConnectionName": "localhost:6379"
  }
}

See the Basic Configuration Settings of the StackExchange.Redis docs for more information on how to format this connection string.

Use configuration providers

The Redis OutputCache component supports Microsoft.Extensions.Configuration. It loads the StackExchangeRedisSettings and ConfigurationOptions from configuration by using the Aspire:StackExchange:Redis key. Example appsettings.json that configures some of the options:

{
  "Aspire": {
    "StackExchange": {
      "Redis": {
        "ConfigurationOptions": {
          "ConnectTimeout": 3000,
          "ConnectRetry": 2
        },
        "DisableHealthChecks": true,
        "DisableTracing": false
      }
    }
  }
}

Use inline delegates

You can also pass the Action<StackExchangeRedisSettings> configureSettings delegate to set up some or all the options inline, for example to disable health checks from code:

builder.AddRedisOutputCache("cache", settings => settings.DisableHealthChecks = true);

You can also setup the ConfigurationOptions using the Action<ConfigurationOptions> configureOptions delegate parameter of the AddRedisOutputCache method. For example to set the connection timeout:

builder.AddRedisOutputCache("cache", configureOptions: options => options.ConnectTimeout = 3000);

AppHost extensions

In your AppHost project, install the Aspire.Hosting.Redis library with NuGet:

dotnet add package Aspire.Hosting.Redis

Then, in the AppHost.cs file of AppHost, register a Redis server and consume the connection using the following methods:

var redis = builder.AddRedis("cache");

var myService = builder.AddProject<Projects.MyService>()
                       .WithReference(redis);

The WithReference method configures a connection in the MyService project named cache. In the Program.cs file of MyService, the redis connection can be consumed using:

builder.AddRedisOutputCache("cache");

Additional documentation

Feedback & contributing

https://github.com/microsoft/aspire

*Redis is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd.

Changes from Previous Version

No structural changes between v13.6.3 and v13.6.4.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 3 target frameworks; confirm the exact target used by your application.The published metadata declares 51 direct dependency entries across framework groups. Inspect the resolved dependency graph for your target framework.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.