Conditional Proxy Caching in Location

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Conditional Proxy Caching in Location

Igal @ Lucee.org
Hello,

I have a variable that shows if a certain cookie exists in the Request, e.g. $req_has_somecookie, and I want to be able to use proxy_cache only for specific URIs, e.g. /slow-page/ if the variable is 0.

I know that "if" is evil as it creates a new location scope.

What's the best way to handle this?

Thanks,

Igal


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Conditional Proxy Caching in Location

Francis Daly
On Sun, Sep 13, 2020 at 03:42:28PM -0700, Igal Sapir wrote:

Hi there,

> I have a variable that shows if a certain cookie exists in the Request,
> e.g. $req_has_somecookie, and I want to be able to use proxy_cache only for
> specific URIs, e.g. /slow-page/ if the variable is 0.
>
> I know that "if" is evil as it creates a new location scope.
>
> What's the best way to handle this?

Probably some combination of http://nginx.org/r/proxy_cache_bypass and
http://nginx.org/r/proxy_no_cache

You may want to change your variable-setting logic; or use a map
(http://nginx.org/r/map) to make a new $skip_the_cache variable that is
0-or-empty when your $req_has_somecookie is not 0, and has a different
value when $req_has_somecookie is 0, so that you can (e.g.)

  proxy_no_cache $skip_the_cache;

in the appropriate location{}s.

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

RE: Conditional Proxy Caching in Location

Igal @ Lucee.org
In reply to this post by Igal @ Lucee.org
Thank you, Francis.  That sounds like a good plan.  

Pardon the new thread but I was subscribed in Digest Mode and couldn't reply directly.

Igal

On Sun, Sep 13, 2020 at 03:42:28PM -0700, Igal Sapir wrote: Hi there, > I have a variable that shows if a certain cookie exists in the Request, > e.g. $req_has_somecookie, and I want to be able to use proxy_cache only for > specific URIs, e.g. /slow-page/ if the variable is 0. > > I know that "if" is evil as it creates a new location scope. > > What's the best way to handle this? Probably some combination of http://nginx.org/r/proxy_cache_bypass and http://nginx.org/r/proxy_no_cache You may want to change your variable-setting logic; or use a map (http://nginx.org/r/map) to make a new $skip_the_cache variable that is 0-or-empty when your $req_has_somecookie is not 0, and has a different value when $req_has_somecookie is 0, so that you can (e.g.) proxy_no_cache $skip_the_cache; in the appropriate location{}s. f -- Francis Daly francis at daoine.org


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx