0

after following some cache tutorials in .ASP Net Core, and performed some local tests i have some doubts related:

Steps I did

I added the header

[ResponseCache(VaryByHeader = "User-Agent", Duration = 180)]

Http responses has the proper header

cache-control: public,max-age=180

Conclusion

Despite the headers are OK, the response is never cached in any browser.

Questions

My first question is, why private caches are not saving that request for that request? The only way to make it working is to configure in the startup :

 app.UseResponseCaching();

But as I have checked it results in an API call that return the data from the cache store in the API/server. Second question is why browser needs to hit the API?

Someone can explain why the browsers are no caching anything? (I have checked that it si enabled in Developer tools)

Many thanks in advance

X.Otano
  • 2,079
  • 1
  • 22
  • 40
  • Not about all browsers, but for Chrome - see [this](https://stackoverflow.com/q/11245767/2501279). – Guru Stron Jun 24 '22 at 09:58
  • As for _"My first question is, why private caches are not saving that request for that request? The only way to make it working is to configure in the startup "_ - because `UseResponseCaching` introduces middleware which caches the response in server side. – Guru Stron Jun 24 '22 at 09:59
  • @GuruStron Yeah thats clear, but why we need API/Server Middleware to process request that should be processed in the client cache? I had checked before your first link, but in my case any browser is caching anything, is not about Chrome. I tried everything stated with no result – X.Otano Jun 24 '22 at 10:11
  • 1) Which browser you have tried 2) what is actual request? – Guru Stron Jun 24 '22 at 10:34
  • 1)Chrome/Firefox 2)A simple GET to a Json with a random number inside – X.Otano Jun 24 '22 at 10:39
  • 1
    @GuruStron I found the solution. See the answer – X.Otano Jun 24 '22 at 11:32

1 Answers1

0

The mistake was that I was using a no-trustable SSL certificate. When that happens, private cache stops working

See more info here: Etags and last-modified over https SSL?

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
X.Otano
  • 2,079
  • 1
  • 22
  • 40