Nginx从Memcached返回损坏的数据 [英] nginx return corrupted data from memcached

查看:63
本文介绍了Nginx从Memcached返回损坏的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站上,我使用memcached进行了数据缓存.它存储完全生成的html页面.下一步是从Nginx的memcached获取此数据,然后将其发送回用户,而不是开始apache进程. 首先,我试图通过php后端从缓存中获取数据,并且它起作用了.但是当我尝试使用Nginx进行此操作时-我几乎看不到损坏的数据.类似于

On my web site i've made data caching with memcached. It stores fully generated html pages. Next step was to get this data from memcached by nginx and send back to user w\o starting apache process. First i tried to get data from cache by php backend and it worked. But when i try make this with nginx - i see hardly corrupted data. smth like

我正在寻求有关此问题的帮助.

i'm asking for help with this problem.

p.s.如果可以的话,这里是nginx配置的一部分

p.s. here the part of nginx config if it can help

location / {
    #add_header    Content-Type  "text/html";
    set $cachable 1;

    if ($request_method = POST){
        set $cachable 0;
        break;
    }
    if ($http_cookie ~ "beauty_logged") {
        set $cachable 0;
        break;
    }

    if ($cachable = 1) {
        set             $memcached_key   'nginx_$host$uri';
        memcached_pass  127.0.0.1:11211;
    }

    default_type    text/html;
    error_page      404 502 504 405 = @php;
    #proxy_pass http://front_cluster;
}

location @php {
    proxy_pass http://front_cluster;
}

推荐答案

问题出在特定的内存缓存行为中.即使您关闭了数据压缩,如果您的数据超过了2万个符号限制,memcached也会这样做.解决方法是-(以我为例)在缓存后端上做一下$this->_memcache->setCompressThreshold(20000, 1);

problem was in specific memcached behavior. even if you turn off data compression, memcached do it if your data exceeds limit in 20k symbols. the cure is - (in my case) on caching backend do smth like $this->_memcache->setCompressThreshold(20000, 1);

p.s.我正在使用Zend_Cache_Backend_Memcached作为后端的父类.所以上面的字符串必须在__contstruct()

p.s. i am using Zend_Cache_Backend_Memcached as a parent class of my backend. so the string above must be at __contstruct()

这篇关于Nginx从Memcached返回损坏的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆