2

I am using OutputCache in .NET7. Outputcache seems not working on IIS while it is working in my local or docker. Is there any configuration to set for IIS server?

builder.Services.AddOutputCache(options =>
{
    options.AddBasePolicy(builder =>
    {
        builder.Expire(TimeSpan.FromDays(1));
    });
});
app.UseOutputCache();

        [HttpGet]
        [OutputCache]
        public async Task<IActionResult> getsomefunction()
        {
            return Ok(somefunction());
        }

Muratkscn
  • 21
  • 2
  • Have you added `app.UseOutputCache();`? – Izzy Dec 21 '22 at 08:59
  • yes it works on docker without any problem. when i publish it to IIS it does not cache the output. – Muratkscn Dec 21 '22 at 09:02
  • _"it does not cache the output."_ - how do you verify that? – Guru Stron Dec 21 '22 at 09:41
  • I am getting first response in 3 seconds while second and others in 50ms. In IIS every responses return in 3 seconds. – Muratkscn Dec 21 '22 at 10:06
  • @Muratkscn that is not a very reliable approach to test caching. – Guru Stron Dec 21 '22 at 12:30
  • how should I test caching then ? @GuruStron – Muratkscn Dec 21 '22 at 13:06
  • I create an endpoint which returns `Guid.NewGuid()` and check if the result is changing. Also based n description output caching should be purely server-side so hosting should not affect it check if your app setup for some reason differ for IIS. – Guru Stron Dec 21 '22 at 13:11
  • You could use [FRT](https://learn.microsoft.com/en-us/iis/troubleshoot/using-failed-request-tracing/troubleshoot-with-failed-request-tracing) to find the cause on IIS. – TengFeiXie Dec 22 '22 at 08:49

0 Answers0