Set up Redis output caching in the AppHost
This article covers the AppHost setup required for the Redis output caching integration. The underlying resource is the standard Redis hosting integration — for the complete AppHost API surface (data volumes, data bind mounts, persistence, parameters, Redis Insights, Redis Commander, and more), see the Redis Hosting integration reference.
If you’re new to the Redis output caching integration, start with Get started with Redis output caching. For how consuming ASP.NET Core apps register the output cache store and use [OutputCache], see Connect to Redis output caching.
Installation
Section titled “Installation”Install the 📦 Aspire.Hosting.Redis NuGet package in your AppHost project:
aspire add redisLearn more about aspire add in the command reference.
Or, choose a manual installation approach:
#:package Aspire.Hosting.Redis@*<PackageReference Include="Aspire.Hosting.Redis" Version="*" />aspire add redisLearn more about aspire add in the command reference.
This updates your aspire.config.json with the Redis hosting integration package:
{ "packages": { "Aspire.Hosting.Redis": "*" }}Add Redis resource
Section titled “Add Redis resource”Once you’ve installed the hosting integration, add a Redis resource and reference it from the consuming ASP.NET Core project:
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache");
var apiService = builder.AddProject<Projects.ApiService>("apiservice") .WithReference(cache);
// After adding all resources, run the app...import { createBuilder } from './.modules/aspire.js';
const builder = await createBuilder();
const cache = await builder.addRedis("cache");
await builder.addProject("apiservice", "../ApiService/ApiService.csproj") .withReference(cache);
// After adding all resources, run the app...More AppHost options
Section titled “More AppHost options”For everything beyond the basic resource declaration — data volumes, data bind mounts, persistence snapshots, custom parameters, Redis Insights, Redis Commander, and connecting to an existing Redis instance — see the Redis Hosting integration reference.