Intermediate caching stores reusable HTTP responses in a proxy or content-delivery service between clients and the origin server. The proxy or CDN can serve later requests directly, using the same HTTP header rules that govern client-side caching. section 3.1.3 section 8.1
For a RESTful API, apply it to frequently accessed GET endpoints, especially requests using default parameters. Static sites may rely heavily on browser and CDN caching, while dynamic sites can combine intermediate response caching with server-side caching for expensive database work. section 8.1
A practical caching decision follows these considerations:
- Cache at the highest level the client and application behavior can safely support. section 8.1
- Use HTTP response headers to control reusable responses across clients and intermediate services. section 3.1.3
- Treat client-specific or permission-specific requests carefully; server-side or distributed caching may better relieve database load when responses vary. section 8.1
// ... [HttpGet(Name = "GetBoardGames")] [ResponseCache(Location = ResponseCacheLocation.Any, Duration = 60)] public IEnumerable<BoardGame> Get() // ...
The board-game API marks its GET endpoint as cacheable for any location with a 60-second duration, providing a concrete ASP.NET Core response-caching configuration. section 3.1.3
