Fill memcached with compressed data, serve directly from nginx Fill memcached with compressed data, serve directly from nginx nginx nginx

Fill memcached with compressed data, serve directly from nginx


The documentation is a little sparse, but if I'm understanding it correctly: memcached_gzip_flag specifies which bits in the flag associated with the cached object indicate the content is already gzipped. You need to say something like: memcached_gzip_flag 1, then store the data with a flag having the matching bits set:

 memcache.set('key', 'gzipped-value', flags=1)


Memcached has a builtin behaviour where if your data is over 20KB, then it will compress it by default. Maybe what is happening there is two-level compression in your case, and the browser just do one data decompression when rendering (given that all headers are fine). Look for Memcached's CompressionThreshold option.


Memcached server has no any compression. A memcached client have to compress/decompress. And clients usually have CompressionThreshold logic

For me, working following configuration with nginx memcached and gunzip modules:

ocation / {  set $memcached_key "$uri?$args";  memcached_pass memcached.up;  memcached_gzip_flag 2; #  net.spy.memcached use second byte for compression flag  default_type text/html;  charset utf-8;  gunzip on;  proxy_set_header Accept-Encoding "gzip";  error_page  404 405 400 500 502 503 504 = @fallback;}

memcached_gzip_flag:

Enables the test for the flag presence in the memcached server response and sets the “Content-Encoding” response header field to “gzip” if the flag is set.