Welcome! Log In Create A New Profile

Advanced

Exclude from cache by content-length

Posted by Andrei 
Andrei
Exclude from cache by content-length
April 16, 2018 10:20AM
Hello!

I have an odd upstream application (out of my control) which sometimes
responds with incomplete pages, and a 200 error.. This causes blank pages
to appear in cache. Is there a way to exclude from/bypass cache if the
content-length header from the upstream is lower than 5kb for example?
Thanks everyone!
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: Exclude from cache by content-length
April 16, 2018 04:30PM
Hello!

On Mon, Apr 16, 2018 at 03:16:13AM -0500, Andrei wrote:

> I have an odd upstream application (out of my control) which sometimes
> responds with incomplete pages, and a 200 error.. This causes blank pages
> to appear in cache. Is there a way to exclude from/bypass cache if the
> content-length header from the upstream is lower than 5kb for example?
> Thanks everyone!

Try proxy_no_cache combined with map on
$upstream_http_content_length. Something like this should work:

map $upstream_http_content_length $nocache {
"~^[0-5][0-9]{,3}" 1;
}

proxy_no_cache $nocache;

See here for details:

http://nginx.org/r/proxy_no_cache
http://nginx.org/r/map
http://nginx.org/r/$upstream_http_

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Andrei
Re: Exclude from cache by content-length
April 17, 2018 06:20AM
Thanks Maxim!

On Mon, Apr 16, 2018 at 9:20 AM, Maxim Dounin <[email protected]> wrote:

> Hello!
>
> On Mon, Apr 16, 2018 at 03:16:13AM -0500, Andrei wrote:
>
> > I have an odd upstream application (out of my control) which sometimes
> > responds with incomplete pages, and a 200 error.. This causes blank pages
> > to appear in cache. Is there a way to exclude from/bypass cache if the
> > content-length header from the upstream is lower than 5kb for example?
> > Thanks everyone!
>
> Try proxy_no_cache combined with map on
> $upstream_http_content_length. Something like this should work:
>
> map $upstream_http_content_length $nocache {
> "~^[0-5][0-9]{,3}" 1;
> }
>
> proxy_no_cache $nocache;
>
> See here for details:
>
> http://nginx.org/r/proxy_no_cache
> http://nginx.org/r/map
> http://nginx.org/r/$upstream_http_
>
> --
> Maxim Dounin
> http://mdounin.ru/
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
_______________________________________________
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