How to send proxy cache status to backend server?

Hello,

I have been using proxy cache of Nginx. It provides response header to
indicate cache status. Is there some way to forward the cache status (in
case of miss, expired or revalidate ) to backend upstream server?

Thanks,
Makailol

Hello!

On Fri, Mar 14, 2014 at 07:35:52PM +0530, Makailol C. wrote:

Hello,

I have been using proxy cache of Nginx. It provides response header to
indicate cache status. Is there some way to forward the cache status (in
case of miss, expired or revalidate ) to backend upstream server?

The proxy_set_header directive should work, see
http://nginx.org/r/proxy_set_header.


Maxim D.
http://nginx.org/

Hi,

I have been using add_header to send cache status to downstream server
or
client like this. This is working fine.
add_header Cache-Status $upstream_cache_status;

Now I tried proxy_set_header to send header to upstream as below.
proxy_set_header Cache-Status $upstream_cache_status;

But this could not send headers to upstream backend server. I think we
can
not use “$upstream_*” variables to send headers to upstream backend.

Would you suggest me some way to send cache-status to backend upstream
server?

Thanks,
Makailol

Thanks, It is working. I was checking wrong variable name.
I have noticed that when catch is being “REVALIDATED”, backend receives
“EXPIRED” and upstream receives “REVALIDATED”. Is this correct ?

Hello!

On Sat, Mar 15, 2014 at 01:14:51PM +0530, Makailol C. wrote:

Would you suggest me some way to send cache-status to backend upstream
server?

The proxy_set_header directive works fine and passes
$upstream_cache_status to backends without any problems. Mostly
likely you did something wrong in your tests.


Maxim D.
http://nginx.org/

Hello!

On Wed, Mar 19, 2014 at 10:19:59AM +0530, Makailol C. wrote:

Thanks, It is working. I was checking wrong variable name.
I have noticed that when catch is being “REVALIDATED”, backend receives
“EXPIRED” and upstream receives “REVALIDATED”. Is this correct ?

Yes, it’s correct. The “REVALIDATED” status is only known after
nginx recieves 304 from a backend. Before this happens, the only
thing known is that response in the cache no longer valid, that
is, status is “EXPIRED”.


Maxim D.
http://nginx.org/

One more thing I would like to know, would it be possible to proxy_pass
request conditionally based on $upstream_cache_status ?

For example here we set request header with proxy_set_header
Cache-Status
$upstream_cache_status; instead we can use condition like below,

if ($upstream_cache_status = “BYPASS”) {
proxy_pass http://someIP;
}

if ($upstream_cache_status = “MISS”) {
proxy_pass http://anotherIP;
}

I tried this but could not find this working. I can set request header
for
backend with proxy_set_header but can not use this variable
conditionally.

Thanks,
Makailol

Hi,

Is there some way to achieve this? I want to pass requests to backend
based
on cache status condition.

Thanks,
Makailol

Hello!

On Wed, Mar 19, 2014 at 03:30:03PM +0530, Makailol C. wrote:

if ($upstream_cache_status = “MISS”) {
proxy_pass http://anotherIP;
}

I tried this but could not find this working. I can set request header for
backend with proxy_set_header but can not use this variable conditionally.

That’s expected, as cache status isn’t known at the rewrite phase
when “if” directives are executed. It’s not even known if a
request will be proxied at all.


Maxim D.
http://nginx.org/

Hi Maxim,

Apart from passing cache status to backend, would it be possible to send
some other headers which are stored in cache?

For example, If backed sets header “Foo : Bar” , which is stored in
cache.
Now when cache is expired , request will be sent to backend. At that
time
can we send the value of Foo header stored in cache to upstream backend?

I tried to achieve this with below code but it could not work.
proxy_set_header Foo $upstream_http_Foo;

Would you suggest me how to achieve this or what am I doing wrong here.

Thanks,
Makailol

Hello!

On Thu, Mar 27, 2014 at 03:01:22PM +0530, Makailol C. wrote:

proxy_set_header Foo $upstream_http_Foo;

Would you suggest me how to achieve this or what am I doing wrong here.

This is not something possible.

which backend will be used. (Note that by default proxy_cache_key


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


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


Maxim D.
http://nginx.org/

Hi,

Would it be possible to add this as new feature?

Is there some other alternative ? Actually based on this header value I
want to select named based location.

Thanks,
Makailol

Hello!

On Thu, Mar 20, 2014 at 09:38:40AM +0530, Makailol C. wrote:

Hi,

Is there some way to achieve this? I want to pass requests to backend based
on cache status condition.

This is not something easily possible, as cache status is only
known after we started processing proxy_pass and already know
which backend will be used. (Note that by default proxy_cache_key
uses $proxy_host, which wouldn’t be known otherwise.)

If you want to check BYPASS as in your previous message, I would
recommend checking relevant conditions from proxy_cache_bypass
separately. As a more generic though less effective aproach, an
additional proxy layer may be used.


Maxim D.
http://nginx.org/

Hello!

On Thu, Mar 27, 2014 at 05:08:31PM +0530, Makailol C. wrote:

Hi,

Would it be possible to add this as new feature?

Is there some other alternative ? Actually based on this header value I
want to select named based location.

Response headers of expires cached responses are not read from a
cache file. If you really want this to happen, you may try to
implement this, but I don’t it’s looks like a generally usable
feature. In most if not all cases it will be just a waste of
resources.

On Thu, Mar 27, 2014 at 03:01:22PM +0530, Makailol C. wrote:

Hi,
If you want to check BYPASS as in your previous message, I would
[email protected]
Maxim D.
http://nginx.org/


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


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


Maxim D.
http://nginx.org/

Hi,

In my configuration I have caching layer of Nginx and a separate proxy
layer which works as reverse proxy to original upstream backend.

As discussed previously we can pass cache status from caching layer to
upstream but is there anything else which I can get from cache file
(when
cache is expired) and pass to upstream?

I want to set some condition to my proxy layer to select original
upstream
based on that.

Thanks,
Makailol

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs