I have enabled caching with Nginx. I followed the official docs and it works fine. What happens is, when the request comes in for the first time, it is proxy passed to a server. The response is cached.
From there on, all requests are served from the Nginx cache until it expires. But I want an additional thing.
Here is what I want:
- When the request is served from the cache, I want to make an API request to my server so that I do not loose on the number of hits (counter)
How can I do this?
I had tried the mirror
command, but it does not get called when the page is served from cache. It only gets called when the cache expires. Here is the config snapshot that I tried. Is this even possible? Any other way to do this?
EDIT Cache directive as highlighted in the second screenshot.