# $memcached\_key doesn't fetch unicode url

**URL:** <https://www.ruby-forum.com/t/memcached-key-doesnt-fetch-unicode-url/240875>\
**Category:** NGINX\
**Created:** [May 4, 2014, 5:44pm UTC](https://www.ruby-forum.com/t/memcached-key-doesnt-fetch-unicode-url/240875 "2014-05-04T17:44:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [May 4, 2014, 5:44pm UTC](https://www.ruby-forum.com/t/memcached-key-doesnt-fetch-unicode-url/240875/1 "2014-05-04T17:44:13Z")

</div>

Hi,

I’m doing some sort of downstream cache that I save every entire page  
into  
memcached from the application with urls such as:

[www.example.com/file/path/?query=1](http://www.example.com/file/path/?query=1)

then I’m fetching them from nginx if available with the config:  
location / {  
# try to fetch from memcached  
set $memcached\_key “$host$request\_uri”;  
memcached\_pass localhost:11211;  
expires 10m;  
# not fetched from memcached, fallback  
error\_page 404 405 502 = @fallback;  
}

This works perfectly fine for latin char urls. However, it fails to  
catch  
unicode urls such as:

[www.example.com/flights/istc-lonc-11062014/lonc-istc-19062014/Cheap-return-tickets-from-İstanbul-to-Londra-in-Haziran.html?class=economy&adult=1](http://www.example.com/flights/istc-lonc-11062014/lonc-istc-19062014/Cheap-return-tickets-from-%C4%B0stanbul-to-Londra-in-Haziran.html?class=economy&adult=1)

The unicode char “%C4%B0” appears same in the nginx logs, application  
cache  
setting key (that is actually taken from raw REQUEST\_URI what nginx  
gives).

The example url content also exist in the memcached itself when if I  
try:  
"get  
[www.example.com/flights/istc-lonc-11062014/lonc-istc-19062014/Cheap-return-tickets-from-İstanbul-to-Londra-in-Haziran.html?class=economy&adult=1](http://www.example.com/flights/istc-lonc-11062014/lonc-istc-19062014/Cheap-return-tickets-from-%C4%B0stanbul-to-Londra-in-Haziran.html?class=economy&adult=1)  
"

However, nginx cannot fetch anything from memcached, @fallbacks every  
time.

I’m using version 1.6.0. Any help is much appreciated.

Roy.

---

<div class="post-metadata">

**Author:** ![kirpit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d9b06d/32.png) [@kirpit](https://www.ruby-forum.com/u/kirpit)\
**Post date:** [May 9, 2014, 3:13am UTC](https://www.ruby-forum.com/t/memcached-key-doesnt-fetch-unicode-url/240875/2 "2014-05-09T03:13:48Z")

</div>

Hello!

On Sun, May 04, 2014 at 06:42:39PM +0300, kirpit wrote:

> ```
> set $memcached_key "$host$request_uri";
> 
> ```

[www.example.com/flights/istc-lonc-11062014/lonc-istc-19062014/Cheap-return-tickets-from-İstanbul-to-Londra-in-Haziran.html?class=economy&adult=1](http://www.example.com/flights/istc-lonc-11062014/lonc-istc-19062014/Cheap-return-tickets-from-%C4%B0stanbul-to-Londra-in-Haziran.html?class=economy&adult=1)

> I’m using version 1.6.0. Any help is much appreciated.

Value of $memcached\_key is escaped to make sure memcached protocol  
constraints are not violated - most notably, space and “%”  
character are escaped into “%20” and “%25”, respectively (space is  
escaped as it’s not allowed in memcached keys, and “%” to make the  
escaping reversible).

Given the

[www.example.com/flights/istc-lonc-11062014/lonc-istc-19062014/Cheap-return-tickets-from-İstanbul-to-Londra-in-Haziran.html?class=economy&adult=1](http://www.example.com/flights/istc-lonc-11062014/lonc-istc-19062014/Cheap-return-tickets-from-%C4%B0stanbul-to-Londra-in-Haziran.html?class=economy&adult=1)

$memcached\_key, nginx will try to fetch

[www.example.com/flights/istc-lonc-11062014/lonc-istc-19062014/Cheap-return-tickets-from-%25C4%25B0stanbul-to-Londra-in-Haziran.html?class=economy&adult=1](http://www.example.com/flights/istc-lonc-11062014/lonc-istc-19062014/Cheap-return-tickets-from-%25C4%25B0stanbul-to-Londra-in-Haziran.html?class=economy&adult=1)

from memcached.

–  
Maxim D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![kirpit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d9b06d/32.png) [@kirpit](https://www.ruby-forum.com/u/kirpit)\
**Post date:** [May 9, 2014, 10:58am UTC](https://www.ruby-forum.com/t/memcached-key-doesnt-fetch-unicode-url/240875/3 "2014-05-09T10:58:32Z")

</div>

A note to the history that is good to know.

Thanks Maxim, even though we choose not to use unicode urls to make  
things  
less complicated.
