agentzh
January 19, 2011 11:08PM
On Wed, Jan 19, 2011 at 5:52 AM, António P. P. Almeida <appa@perusio.net> wrote:
> >
> > Any chance of implementing ...
> > [code]
> > proxy_cache_bypass_empty $cookie_COOKIE;
> > proxy_no_cache_empty $cookie_COOKIE;
> > [/code]
>
> If I understand your question, wouldn't this do the trick?
>
> if ($cookie_COOKIE = "") {
>  set $cookie_no_cache true;
> }
>
> Now it works as "usual".

Nginx's "if" is evil and can be even more evil when you use it a bit
more. The code snippet above can only work when being put into the
"server" block rather than the "location" block :)

I believe this is a perfect use case for ngx_lua:

location / {
set_by_lua $no_cache '
if ngx.var.cookie_COOKIE == "" or ngx.var.cookie_COOKIE == nil then
return 1
end
return ""
';
proxy_cache_bypass $no_cache;
proxy_pass ...
}

Actually you can implement even more complicated caching policy this
way because Lua is a turing complete language and also has great
performance ;)

See https://github.com/chaoslawful/lua-nginx-module for more details.

Cheers,
-agentzh

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Skipping the proxy cache based on a cookie?

ehudros2 December 29, 2010 09:15AM

Re: Skipping the proxy cache based on a cookie?

ehudros2 December 30, 2010 08:27AM

Re: Skipping the proxy cache based on a cookie?

Dayo January 01, 2011 10:52AM

Re: Skipping the proxy cache based on a cookie?

ehudros2 January 02, 2011 07:28AM

Re: Skipping the proxy cache based on a cookie?

Dayo January 18, 2011 04:34PM

Re: Skipping the proxy cache based on a cookie?

António P. P. Almeida January 18, 2011 05:00PM

Re: Skipping the proxy cache based on a cookie?

agentzh January 19, 2011 11:08PM

Re: Skipping the proxy cache based on a cookie?

António P. P. Almeida January 20, 2011 03:38PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 18, 2011 05:18PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 19, 2011 01:44PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 19, 2011 01:45PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 19, 2011 02:06PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 19, 2011 02:07PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 19, 2011 05:19PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 19, 2011 02:58PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 19, 2011 04:49PM

Re: Skipping the proxy cache based on a cookie?

António P. P. Almeida January 19, 2011 03:20PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 19, 2011 03:43PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 19, 2011 04:22PM

Re: Skipping the proxy cache based on a cookie?

António P. P. Almeida January 19, 2011 04:10PM

Re: Skipping the proxy cache based on a cookie?

Eugaia January 19, 2011 04:30PM

Re: Skipping the proxy cache based on a cookie?

António P. P. Almeida January 19, 2011 04:36PM

Re: Skipping the proxy cache based on a cookie?

António P. P. Almeida January 19, 2011 08:30PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 20, 2011 03:08PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 21, 2011 03:51PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 21, 2011 03:52PM

Re: Skipping the proxy cache based on a cookie?

Dayo January 21, 2011 04:17PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 264
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready