I'm struggling to get response caching in an ASP.NET Core 2.0 web API working.
I've added response caching in the middleware:
public void ConfigureServices(IServiceCollection services)
{
services.AddResponseCaching();
...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseResponseCaching();
...
}
Here my action method code:
[ResponseCache(Duration = 30)]
[HttpGet()]
public IActionResult GetLookups()
{
Lookup lookups = dataRepository.GetContactLookups();
}
Here's the postman request and response:
So, I'm getting the correct Cache-Control http header in the response but if I send the response again from postman, it still calls my code in my action method. I expected it to not call my code and use the cached response.
Am I misunderstanding the way that response caching works? Any help would be appreciated.
The problem with Postman you have to disable Send-No-Cash header ( no-cache header makes sure you get the freshest response from your server)
ASP.NET Core 2.0 Web API Response Caching
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With