如何在 Magento 中查找 memcached 密钥的来源

How to find where a memcached key originates from in Magento

我们 运行 Magento EE 1.13 将 memcached 作为我们的 "fast" 缓存,将 redis 作为 "slow" 缓存。我们有一个特定的 memcached 键,它每秒收到大约 70 个获取请求,但命中率为 0%。这只发生在我们的生产站点上,它有多个前端服务器和一个单独的数据库服务器。

似乎从未设置过此特定密钥,但我们无法找到该密钥的来源。该密钥使用 md5 哈希 "AA_B1B5D70089938E5C32F61E616FD3908D",因此这无助于缩小范围。

我在哪里可以找到此密钥的来源?

我想通了。在 app/code/core/Mage/Core/Model/App.php 中查找:

public function loadCache($id)
{
    return $this->_cache->load($id);
}

在此函数中是您要添加临时检查的位置:

public function loadCache($id)
{
    if (strstr($id, 'b1b5d70')) {
        $currentUrl = Mage::helper('core/url')->getCurrentUrl();
        $cacheId = $this->_cache->load($id);
        $stack = Varien_Debug::backtrace(true, true);
        Mage::log("Mage_Core_Model_App: " . $id, null, "memcacheKeys.log", true);
        Mage::log($currentUrl, null, "memcacheKeys.log", true);
        Mage::log($cacheId, null, "memcacheKeys.log", true);
        Mage::log($stack, null, "memcacheKeys.log", true);
    }
    return $this->_cache->load($id);
}

我们正在检查此处的部分内存缓存密钥,'b1b5d70'。此时密钥尚未转换为大写。 local.xml、'AA_'中定义的前缀也还没有添加。

保存到您日志中的回溯应该会告诉您密钥是在哪里生成的。就我而言,它追溯到 'app/code/core/Mage/Catalog/Block/Product/Price.php'.