内存缓存 - 从内存缓存中删除的值重新出现

Memcache - values deleted from memcache reappearing

我正在使用内存缓存来存储 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。但是,当我刷新脚本(并建立与内存缓存的新连接)时,数据会重新弹出,就好像内存缓存状态没有更新一样。我尝试使用 replace 代替(具有某些特定值),效果相同 - 值不会更新。

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

在手册页上有一条 5 年前关于 PECL 版本和 memcached 之间不兼容的神秘信息(但那是 5 年前的事了)。有人可以向我解释可能会发生什么吗?

我在 PHP 5.6

上使用 memcached 1.4.21 和 memcache (PECL) 3.0.8

一种对我非常有效的方法是使用相同的密钥再次设置缓存,但将到期时间放在 Now 之前几秒。这会使该密钥在您的缓存中过期。 C# 代码是这样的:

memcachedCache.Set(objectName, yourvalue, DateTime.Now.AddSeconds(-10)); 

问题源于对它的使用:

$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 - 中断行为是在 memcache (2.2.x)

中引入的

如果有人想要调查此行为,我会继续悬赏