Memcache - 从memcache中删除的值重新出现

问题描述 投票:5回答:2

我正在使用memcache来存储Zend_Config(和其他值) - 我设置的值如下:

$memcache = new Memcache();
...

if (!$config = $memcache->get($memcache->unique_key.APPLICATION_DOMAIN."#config"))
{
    ...
    $memcache->set($memcache->unique_key.APPLICATION_DOMAIN."#config", $config);
}

我正在删除如下值:

$memcache->delete($key);

从memcache删除值后,它正确地显示在与删除相同的连接中 - 正确调用$memcache->get($key)给了我NULL。但是,当我刷新脚本(并与memcache建立新连接)时,数据会弹回,就好像memcache状态没有更新一样。我尝试使用replace(具有一些特定值),达到相同的效果 - 值不会更新。

调用$memcache->flush()工作,并从memcache中删除所有内容,但我想删除特定的键。

在手册页上有一个5年前的一个神秘的消息,关于PECL版本和memcached之间的不兼容性(但是从5年前开始)。有人可以向我解释可能会发生什么吗?

我在PHP 5.6上使用memcached 1.4.21和memcache(PECL)3.0.8

php memcached
2个回答
7
投票

问题源于使用此:

$list = array();
$allSlabs = $memcache->getExtendedStats('slabs');

foreach ($allSlabs as $server => $slabs)
    foreach ($slabs as $slabId => $slabMeta)
        foreach ($memcache->getExtendedStats('cachedump', (int) $slabId) as $entries)
            if (!empty($entries))
                foreach ($entries as $key => $entry)
                    if (strpos($key, $memcache->unique_key) === 0)
                    {
                        $value = $memcache->get($key);
                        $list[$key] = is_string($value) && unserialize($value) ? unserialize($value) : $value;
                    }

(你会注意到它没有包含在我的原始查询中,因为它没有做任何事情,但是列出了存储在memcached中的键/值)

这个功能的问题在于它显然是静默地导致memcached成为只读的。虽然更新函数的后续调用所提供的值(因为,我认为它们是从本地内存中检索的),但memcached服务中的值不是。

此行为会影响当前最新版本的memcached - 在memcache(2.2.x)中引入了中断行为

如果有人想调查这种行为,我会保持开放


0
投票

一种对我很有用的方法是使用相同的密钥再次设置缓存,但在Now之前将到期时间设置为几秒。这使得该密钥在缓存中到期。 c#代码是这样的:

memcachedCache.Set(objectName, yourvalue, DateTime.Now.AddSeconds(-10)); 
© www.soinside.com 2019 - 2024. All rights reserved.