ASPNET Caching — Response and Output Caching in ASP.NET Core
DodaTech
Updated 2026-06-28
1 min read
In this tutorial, you'll learn about ASPNET Caching. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
ASP.NET Core provides multiple caching layers from in-memory to distributed caching for improving application performance.
// Output caching (ASP.NET Core 7+)
builder.Services.AddOutputCache(options =>
{
options.AddBasePolicy(policy => policy.Expire(TimeSpan.FromMinutes(10)));
options.AddPolicy("ScanResults", policy =>
policy.Expire(TimeSpan.FromMinutes(5))
.SetVaryByQuery("fileId")
.Tag("scans"));
});
app.UseOutputCache();
[OutputCache(PolicyName = "ScanResults")]
public async Task<IActionResult> GetScanResult(string fileId)
{
var result = await _scanService.GetResultAsync(fileId);
return Ok(result);
}
// Cache invalidation
// app.MapPost("/api/scan", async () => { ... }).CacheOutput(x => x.NoCache());
Output caching reduces server load by serving cached responses for identical requests.
← Previous
ASPNET CORS Deep Dive — Cross-Origin Resource Sharing in .NET
Next →
ASPNET Globalization — Internationalization in ASP.NET Core
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro