wiki:MemcachedGzip

memcached_gzip

Git repository: git clone git://openhack.ru/nginx-patched.git branch memcached_gzip.

This extension allows nginx to serve compressed data from memcached:

memcached_pass        memcached_cluster;
memcached_gzip_flag   2;
gunzip                on;

syntax: memcached_gzip_flag mask
default: memcached_gzip_flag 0
context: http, server, location, location-if

Non-zero memcached_gzip_flag enables the extension. The value is a bit mask (in decimal) of the flag that is used to signal compressed data. Most memcached clients use 0x2 for this (see  http://www.hjp.at/zettel/m/memcached_flags.rxml).


syntax: gunzip on|off
default: gunzip off
context: http, server, location, location-if

gunzip enables automatic data decompression, but only if the client can't accept compressed data.

When memcached_gzip_flag is enabled but gunzip is not, and the data retrieved from memcached is compressed but the client can't accept compressed data, nginx will pretend that nothing was found on this memcached server, and will fall back to some other server according to the used load balancer (using memcached_hash would be most appropriate, in this case nginx will fall back to some HTTP backend, that will return uncompressed data). When memcached_gzip_flag is not set (or set to zero) the extension is disabled, and all data is sent to the client as-is.

Decompression will use buffers specified with gzip_buffers.

Note that it's perfectly makes sense to have both gzip on and gunzip on. The first setting will affect interaction with clients that can accept compressed data: plain data will be compressed for them. The second setting will affect interaction with clients that can't accept compressed data: pre-compressed data will be decompressed for them.