# Are numbered captures available to the proxy cache key construct?

**URL:** <https://www.ruby-forum.com/t/are-numbered-captures-available-to-the-proxy-cache-key-construct/195243>\
**Category:** NGINX\
**Created:** [September 20, 2010, 1:24pm UTC](https://www.ruby-forum.com/t/are-numbered-captures-available-to-the-proxy-cache-key-construct/195243 "2010-09-20T13:24:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![portante](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@portante](https://www.ruby-forum.com/u/portante)\
**Post date:** [September 20, 2010, 1:24pm UTC](https://www.ruby-forum.com/t/are-numbered-captures-available-to-the-proxy-cache-key-construct/195243/1 "2010-09-20T13:24:55Z")

</div>

Hi Folks,

Can somebody comment on whether proxy\_cache\_key is supposed to be able  
to handle # captures? I believe the below example shows how I want to  
use it, but I can’t get it to work.

Thanks,

-peter

```auto
location ~ ^/api/rest/\d+/(.+)/.+/*$ {
    proxy_cache apiCache;
    proxy_cache_valid 200 7d;
    proxy_cache_use_stale updating;
    proxy_cache_key "$host.$1";
    if ($upstream_http_content_encoding !~* "") { gzip off; }
    proxy_pass http://127.0.0.1:8080$request_uri;
}
```

Posted at Nginx Forum:

> **[Are numbered captures available to the proxy cache key construct?](https://forum.nginx.org/read.php?2,132186,132186#msg-132186)**
>
> Hi Folks, Can somebody comment on whether proxy\_cache\_key is supposed to be able to handle # captures? I believe the below example shows how I want to use it, but I can't get it to work. Thanks, -peter \[code\] location ~

---

<div class="post-metadata">

**Author:** ![portante](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@portante](https://www.ruby-forum.com/u/portante)\
**Post date:** [September 20, 2010, 2:18pm UTC](https://www.ruby-forum.com/t/are-numbered-captures-available-to-the-proxy-cache-key-construct/195243/2 "2010-09-20T14:18:11Z")

</div>

Hello!

On Mon, Sep 20, 2010 at 07:24:30AM -0400, portante wrote:

> ```auto
> location ~ ^/api/rest/\d+/(.+)/.+/*$ {
> proxy_cache apiCache;
> proxy_cache_valid 200 7d;
> proxy_cache_use_stale updating;
> proxy_cache_key "$host.$1";
> if ($upstream_http_content_encoding !~* "") { gzip off; }
> proxy_pass http://127.0.0.1:8080$request_uri;
> }
> ```

Regexp match in “if” directive will be executed (and will reset  
enumerated captures) before proxy module will have cance to grab  
$1. Use named captures as available in 0.8.25+ to avoid such  
problems.

Additionally, “if” directive in question is useless due to the  
following reasons:

- $upstream\_\* variables are only available after nginx got reply  
from upstream, while rewrite directives are executed at rewrite  
phase - before we even send request to upstream.

- gzip module is smart enough to don’t re-encode replies which  
already have content-encoding applied.

Maxim D.
