Welcome! Log In Create A New Profile

Advanced

Actions after cache miss is detected

Posted by Roger Fischer 
Roger Fischer
Actions after cache miss is detected
August 10, 2018 06:10PM
Hello,

Is there a way to perform an action after a cache miss is detected but before the request is forwarded to the upstream server?

Specifically, on a cache miss I want to:
Return a response instead of forwarding the request to the upstream server.
Trigger a handler (module or script) that executes asynchronously to the request.

The latter I could do by looking at the logs. But I was wondering if there is a more elegant way.

Thanks…

Roger



_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: Actions after cache miss is detected
August 12, 2018 11:30PM
Hello!

On Fri, Aug 10, 2018 at 09:05:30AM -0700, Roger Fischer wrote:

> Is there a way to perform an action after a cache miss is
> detected but before the request is forwarded to the upstream
> server?
>
> Specifically, on a cache miss I want to:
> Return a response instead of forwarding the request to the
> upstream server.
> Trigger a handler (module or script) that executes
> asynchronously to the request.
>
> The latter I could do by looking at the logs. But I was
> wondering if there is a more elegant way.

There is no direct way to do this. There are multiple of ways to
do this indirectly though, including:

- configure a backend which returns a non-cacheable response and
triggers appropriate actions;

- configure a non-responding backend and error_page 502 to return
a response and trigger appropriate processing.

Alternatively, in some cases it might be more convenient to use
proxy_store instead of proxy_cache, and then work with responses
on the file system - with try_files and so on.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login