Caching improves application performance by reusing previously retrieved data instead of repeating expensive work. In ASP.NET Core, caching can reduce browser requests, server response generation, or calls to remote services. section 22.1.3 section 34.1.1
Choose the caching approach according to where the stored response should live:
- Response caching uses the ResponseCacheFilter, exposed through the [ResponseCache] attribute, to add HTTP caching headers. The client may reuse a response, but the server does not store it. section 22.1.3
- Output caching stores generated responses on the server and reuses them for later requests. ASP.NET Core introduced it in .NET 7, with storage configurable for memory or another location such as a database. section 22.1.3
- A background cache fetches remote data ahead of time, allowing an API endpoint to read quickly from shared cached state rather than making an HTTP call for every request. section 34.1.1
Keeping exchange-rate requests fast
Register an ExchangeRatesCache as a singleton and run an ExchangeRatesHostedService derived from BackgroundService. The service periodically calls a typed HTTP client and updates the cache; the endpoint reads directly from that cache. This keeps endpoint latency consistent while allowing the data to be refreshed. Avoid awaiting long-running work directly in StartAsync unless blocking application startup is intentional. section 34.1.1





































