[英]Memcached - Why data is not stored?
I'm actually trying to understand why memcached is not storing data for a give Id. 我实际上是想了解为什么memcached不存储给定ID的数据。
I'm using Magento EE 1.11.2.0 that is based on Zend Framework 1.11.1. 我正在使用基于Zend Framework 1.11.1的Magento EE 1.11.2.0。 The interface used to deal with memcached is
Zend_Cache_Backend_Memcached
用于处理memcached的接口是
Zend_Cache_Backend_Memcached
Now there is not such big custom code here, this is my custom container that save the cache: 现在这里没有这么大的自定义代码,这是我的自定义容器,用于保存缓存:
public function saveCache($blockContent)
{
$lifeTime = 86400 * 30 * 6;
$tags = array(
My_Module_Model_PageCache_Container_Category_Blabla::CACHE_TAG
);
$cacheId = $this->_getCacheId();
if ($cacheId !== false) {
$this->_saveCache($blockContent, $cacheId, $tags, $lifeTime);
}
return $this;
}
I'm just forcing magento to use my custom cache tag
and a fixed lifetime
( memcache doens't support custom tag so I guess this is not the problem ) also my lifetime
is not used in memcached because I can see that the default one is used. 我只是强迫magento使用我的自定义
cache tag
和固定的lifetime
(memcache不支持自定义标签,所以我想这不是问题),而且我的lifetime
未在memcached中使用,因为我可以看到默认的是用过的。
At the beginning I thought the issue was caused by a to long cache ID but now after reducing it ( <31 char ) this didn't help me: 一开始我以为这个问题是由缓存ID太长引起的,但是现在减少它(<31 char)后,这对我没有帮助:
I can see that the load()
method Zend_Cache_Backend_Memcached
return always false for my cache ids. 我可以看到
load()
方法Zend_Cache_Backend_Memcached
对于我的缓存ID总是返回false。 While the save()
method return true like if it was cached. 尽管
save()
方法返回true就像被缓存一样。
This is my local.xml configuration: 这是我的local.xml配置:
<cache>
<slow_backend_store_data>1</slow_backend_store_data>
<auto_refresh_fast_cache>0</auto_refresh_fast_cache>
<backend>memcached</backend>
<slow_backend>database</slow_backend>
<memcached>
<servers>
<!--<server>-->
<!--<host><![CDATA[127.0.0.1]]></host>-->
<!--<port><![CDATA[11213]]></port>-->
<!--<persistent><![CDATA[1]]></persistent>-->
<!--</server>-->
<server>
<host><![CDATA[unix:///tmp/memcached.sock]]></host>
<port><![CDATA[0]]></port>
<persistent><![CDATA[0]]></persistent>
<weight><![CDATA[2]]></weight>
<timeout><![CDATA[5]]></timeout>
</server>
</servers>
<compression><![CDATA[0]]></compression>
<hashed_directory_level><![CDATA[]]></hashed_directory_level>
<hashed_directory_umask><![CDATA[]]></hashed_directory_umask>
<file_name_prefix><![CDATA[]]></file_name_prefix>
</memcached>
</cache>
<full_page_cache>
<backend>memcached</backend>
<slow_backend>database</slow_backend>
<slow_backend_store_data><![CDATA[1]]></slow_backend_store_data>
<memcached>
<servers>
<server>
<host><![CDATA[unix:///tmp/memcached.sock]]></host>
<port><![CDATA[0]]></port>
<persistent><![CDATA[0]]></persistent>
<weight><![CDATA[2]]></weight>
<timeout><![CDATA[10]]></timeout>
<retry_interval><![CDATA[10]]></retry_interval>
<status><![CDATA[1]]></status>
<stats_update_factor><![CDATA[1]]></stats_update_factor>
</server>
</servers>
</memcached>
</full_page_cache>
I also tried to check the entry of memcached to see if my id was stored or not with this command: 我还尝试使用以下命令检查memcached的条目,以查看是否存储了我的ID:
echo 'stats cachedump 35 35' | sudo nc -U /tmp/memcached.sock
Zend_Cache_Backend_Memcached
with xdebug) Zend_Cache_Backend_Memcached
) You can restart memcached with -vv and look at the interactions. 您可以使用-vv重新启动memcached并查看交互。
BTW, the default port for memcache is 11211. FYI 顺便说一句,内存缓存的默认端口是11211。
here the issue is $lifetime and a relative bug in Zend_Cache_Backend_Memcached. 这里的问题是$ lifetime和Zend_Cache_Backend_Memcached中的一个相对错误。
Memcached has a max lifetime of 30 days (2592000) so the limit I was using it was too big and that is why the data was not stored. Memcached的最大生命周期为30天(2592000),所以我使用的限制太大了,这就是为什么不存储数据的原因。
Sadly: 可悲的是:
Zend_Cache_Backend_Memcached::save() doesn't check if the limit is correct < 2592000 Zend_Cache_Backend_Memcached :: save()不检查限制是否正确<2592000
the set() method on the memcached object return true even if it doesn't store the data $result = @$this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime); 即使 memcached对象上的set()方法不存储数据,它也返回true $ result = @ $ this-> _ memcache-> set($ id,array($ data,time(),$ lifetime),$标志,$ lifetime);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.