proxy_cache_background_update after cache expiry

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

proxy_cache_background_update after cache expiry

anish10dec
Hello,

I'm trying to configure nginx to use proxy_cache_background_update but it
seems like after expiry it still waits for the full roundtrip to the
backend, returning a MISS in X-Cache-Status. What am I MISSing?

I'm using nginx 1.11.12 under ubuntu 14.04 running inside docker, but
hopefully this is too much detail.

location ~ ^/?(\d+/[^/]+)?/?$
{
   expires 20s;

   proxy_cache app_cache;
   proxy_cache_lock on;

   proxy_cache_bypass $http_upgrade;

   proxy_pass <a href="http://172.17.0.2:5000;">http://172.17.0.2:5000;
   proxy_http_version 1.1;
   error_log    /nginxerror.log debug;

   add_header X-Cache-Status $upstream_cache_status;

   proxy_cache_use_stale error timeout updating http_500 http_502 http_503
http_504;
   proxy_cache_background_update on;

   break;
}

NB: This is a duplicate of my so question, I was kindly advised on the nginx
IRC to repost here for better chances, the original question is here:
http://stackoverflow.com/questions/43223993/nginx-proxy-cache-background-update-after-cache-expiry

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,273417,273417#msg-273417

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

Re: proxy_cache_background_update after cache expiry

Jean-Paul Hemelaar
Hi,

I have a similar issue:

I noticed (using tcpdump) that all data except the last package is send immediately.
Can you verify it that's happening in your case as well?

JP

On Wed, Apr 5, 2017 at 1:32 PM, IgorR <[hidden email]> wrote:
Hello,

I'm trying to configure nginx to use proxy_cache_background_update but it
seems like after expiry it still waits for the full roundtrip to the
backend, returning a MISS in X-Cache-Status. What am I MISSing?

I'm using nginx 1.11.12 under ubuntu 14.04 running inside docker, but
hopefully this is too much detail.

location ~ ^/?(\d+/[^/]+)?/?$
{
   expires 20s;

   proxy_cache app_cache;
   proxy_cache_lock on;

   proxy_cache_bypass $http_upgrade;

   proxy_pass http://172.17.0.2:5000;
   proxy_http_version 1.1;
   error_log    /nginxerror.log debug;

   add_header X-Cache-Status $upstream_cache_status;

   proxy_cache_use_stale error timeout updating http_500 http_502 http_503
http_504;
   proxy_cache_background_update on;

   break;
}

NB: This is a duplicate of my so question, I was kindly advised on the nginx
IRC to repost here for better chances, the original question is here:
http://stackoverflow.com/questions/43223993/nginx-proxy-cache-background-update-after-cache-expiry

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,273417,273417#msg-273417

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


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

Re: proxy_cache_background_update after cache expiry

Maxim Dounin
In reply to this post by anish10dec
Hello!

On Wed, Apr 05, 2017 at 07:32:01AM -0400, IgorR wrote:

> Hello,
>
> I'm trying to configure nginx to use proxy_cache_background_update but it
> seems like after expiry it still waits for the full roundtrip to the
> backend, returning a MISS in X-Cache-Status. What am I MISSing?
>
> I'm using nginx 1.11.12 under ubuntu 14.04 running inside docker, but
> hopefully this is too much detail.
>
> location ~ ^/?(\d+/[^/]+)?/?$
> {
>    expires 20s;
>
>    proxy_cache app_cache;
>    proxy_cache_lock on;
>
>    proxy_cache_bypass $http_upgrade;
>
>    proxy_pass <a href="http://172.17.0.2:5000;">http://172.17.0.2:5000;
>    proxy_http_version 1.1;
>    error_log    /nginxerror.log debug;
>
>    add_header X-Cache-Status $upstream_cache_status;
>
>    proxy_cache_use_stale error timeout updating http_500 http_502 http_503
> http_504;
>    proxy_cache_background_update on;
>
>    break;
> }

"MISS" in $upstream_cache_status indicate that the relevant
resource is not present in the cache, and therefore there is
no stale response to return.

Most likely the problem is the resource was never saved to the
cache, because of the cacheability flags in the response.  
Consider testing if the resource is at all saved to cache,
the proxy_cache_background_update is certainly irrelevant.

Note that cacheability of a resource is determinded by nginx based
on multiple factors.  Cache-Control, Expires, X-Accel-Expires,
Set-Cookie, and Vary response headers affect caching.  If there
are no response headers which explicitly allow caching and set
expiration time, only responses with appropriate proxy_cache_valid
are cached.

For more information see http://nginx.org/r/proxy_cache_valid.

--
Maxim Dounin
http://nginx.org/
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: proxy_cache_background_update after cache expiry

anish10dec
In reply to this post by anish10dec
thank you Maxim,

the resourse was saved to cache but was quickly expiring in the browser
causing a Cache-Control: no-cache header to be sent.

Sending something like

Cache-Control:
public,max-age=15,s-maxage=240;must-revalidate,stale-while-revalidate=240

together with Last-Modified/ETag from the upstream server seem to be getting
me where I want.

Thanks for pointing me in the right direction.


@jeanpaul: I didn't have the chance to check your idea since taking a closer
look at the headers really helped moving forward.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,273417,273439#msg-273439

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