python - Fill memcached with compressed data, serve directly from nginx -
in python generate complex static pages. put them memcached next time they're requested, can served directly nginx (without hitting python @ all)
this worked great until realized how inefficient store uncompressed html in nginx. tried manually gzip data before storing it, , nginx return directly (just setting content-encoding:gzip), although nginx's documentation suggests it's possible, haven't been able work.
in test, had python fill cache data gzip in python via npe's answer @ how gzip compress string in python? . set memcached flag these 1.
with no other changes, @ point, nginx serves raw data, gets displayed junk in browser.
after that, changed nginx settings location, setting memcached_gzip_flag
field 1 nginx know data gzipped, nginx still served raw data. i've experimented every combination of nginx's settings: gzip on
, memcached_gzip_flag 1
in cases browser displays raw data (after first direct python hit); in cases firebug reports content-encoding gzip (but still showing raw gzip data) , in others, content-encoding not set.
overall, plan of attack trick nginx serving already-compressed data right headers browsers unzip it.
i'm in nginx 1.6 & memcached 1.4.13
here's related nginx config lines, work. first hit gets data python fills cache, 2nd hit serves directly memcached.
location ~* <matching stuff> { if ($request_method = post){ break; } memcached_gzip_flag 1; set $memcached_key $uri; memcached_pass 127.0.0.1:11211; error_page 404 405 502 = @redo; default_type text/html; }
update: experimented more (details in comments), still no result.
update post bounty: have no answer @ this. basically, can't memcached_gzip_flag
function work @ all. note future answerers: if answer make bounty & award you. preferable having half of bounty automatically awarded wrong answers.
the documentation little sparse, if i'm understanding correctly: memcached_gzip_flag
specifies bits in flag
associated cached object indicate content gzipped. need like: memcached_gzip_flag 1
, store data flag having matching bits set:
memcache.set('key', 'gzipped-value', flags=1)
Comments
Post a Comment