Skip to content

Output Caching support for Wolverine.HTTP endpoints #2402

@jeremydmiller

Description

@jeremydmiller

Summary

Wolverine.HTTP currently supports [ResponseCache] for client-side cache headers but has no integration with ASP.NET Core's server-side output caching middleware. There's no way to declaratively apply output caching to a Wolverine endpoint.

Proposal

Add output caching support to Wolverine.HTTP via:

  1. New attribute — e.g. [WolverineOutputCache] or [CachedResponse] that can be applied to endpoint methods to opt into server-side output caching with policy configuration (duration, vary-by, tags for invalidation)
  2. New Wolverine.HTTP middleware — code-generated middleware that integrates with ASP.NET Core's OutputCacheMiddleware infrastructure, handling cache storage and retrieval
  3. Integration with [Entity] loader and persistence codegen — the output caching middleware must be aware of existing entity loading patterns. If an endpoint uses [Entity] or other persistence loading attributes, the caching layer needs to:
    • Short-circuit entity loading on cache hits (avoid unnecessary DB queries)
    • Properly integrate with the code generation pipeline so the cache check runs before persistence loading in the generated handler code
  4. Tag-based cache invalidation — ability to invalidate cached responses when related data changes (e.g. via message handlers or side effects)

Implementation Considerations

  • The code generation must place the cache check before any [Entity]/persistence loading in the generated pipeline to avoid unnecessary database round-trips on cache hits
  • Should support ASP.NET Core's existing output cache policies and tag-based eviction
  • Consider how this interacts with multi-tenancy (tenant-specific cache keys)
  • Consider interaction with authorization (authenticated vs anonymous caching)
  • ETag/conditional request support (304 Not Modified) would be a natural companion feature

Context

All comparable frameworks support output caching:

  • Minimal APIs: built-in .CacheOutput() with policies, tag-based invalidation (.NET 7+)
  • MVC: [OutputCache] attribute with the same middleware
  • FastEndpoints: uses ASP.NET Core output caching middleware directly

Output caching can dramatically reduce load for read-heavy endpoints and is a commonly expected feature for production APIs.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions