Jul 4, 2024
app.UseResponseCaching()
in program.cs
to include caching middleware.[ResponseCache(Duration = 60)]
to cache response for 60 seconds.builder.Services.AddMemoryCache()
before builder.Build()
in program.cs
.private readonly IMemoryCache _memoryCache
and initialize in the controller’s constructor.const string cacheKey = "result"
)._memoryCache.TryGetValue(cacheKey, out var forecast)
._memoryCache.Set(cacheKey, forecast, cacheOptions)
.