Get started with Redis output caching
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
The Redis® output caching integration is the [OutputCache]-flavored layer over the Redis hosting integration. It registers an ASP.NET Core Output Caching store backed by Redis using the Aspire.StackExchange.Redis.OutputCaching package — so your controllers and minimal API endpoints can use [OutputCache] or services.AddOutputCache() without any manual connection wiring.
Why use Redis output caching with Aspire
Section titled “Why use Redis output caching with Aspire”Adding Redis output caching through Aspire gives you:
- Drop-in
IOutputCacheStoreimplementation. A singleAddRedisOutputCachecall replaces the default in-memory store with a Redis-backed one that works across app replicas. - Automatic registration. Aspire wires up the Redis connection from the AppHost reference — no connection strings to manage by hand.
[OutputCache]attribute support. Works with the standard[OutputCache(Duration = 60)]attribute,CacheOutput()extension, andservices.AddOutputCache()— no special API needed.- Built-in health checks. The client integration registers a health check that verifies the Redis instance is reachable and command-ready.
- OpenTelemetry telemetry. Logging, distributed tracing, and metrics are configured automatically through OpenTelemetry.
How the pieces fit together
Section titled “How the pieces fit together”The Redis output caching integration has two sides: a hosting integration that you use in your AppHost to model the Redis resource, and a client integration that the consuming ASP.NET Core app uses to register the output cache store.
architecture-beta group apphost(server)[AppHost] group consumer(server)[ASP NET Core app] service hosting(server)[Hosting integration] in apphost service redis(server)[Redis server] in apphost service client(iconoir:server-connection)[StackExchange Redis output cache client] in consumer service app(server)[App] in consumer hosting:R --> L:redis redis:R --> L:client client:R --> L:app
The hosting integration lives in your AppHost project and models the Redis server as a resource. The client integration lives in your ASP.NET Core project and uses the connection information Aspire injects to register IOutputCacheStore.
Getting there is a two-step process: model the Redis resource in your AppHost, then connect to it from each app that needs output caching.
-
Set up Redis in your AppHost
Section titled “Set up Redis in your AppHost”Add the Redis hosting integration to your AppHost, then declare a Redis resource and reference it from the apps that need it. See Set up Redis output caching in the AppHost for the installation steps and basic resource declaration. For the full AppHost API surface — data volumes, persistence, parameters, Redis Insights, and more — refer to the main Redis Hosting integration.
Set up Redis output caching in the AppHost
-
Connect from your ASP.NET Core app
Section titled “Connect from your ASP.NET Core app”When you reference a Redis resource from a consuming project, Aspire injects its connection information as environment variables. See Connect to Redis output caching for the connection properties reference, the
AddRedisOutputCacheregistration, configuration patterns, health checks, telemetry, and usage examples with[OutputCache].Connect to Redis output caching
See also
Section titled “See also”- Redis integration — the underlying hosting and client integration this builds on.
- Redis distributed caching —
IDistributedCachevariant backed by the same Redis resource. - Redis hosting extensions — community toolkit extensions for the Redis hosting integration.