【问题标题】:Session value not working when FPC cache enabled启用 FPC 缓存时会话值不起作用
【发布时间】:2017-09-11 12:25:23
【问题描述】:

启用 FPC 缓存时,会话值在块中不起作用。如何处理启用缓存的块中的会话值。我添加了客户会话 ID,如下所示。如何从块中的缓存中获取客户 ID。

public function getCacheKeyInfo() {
    $info = parent::getCacheKeyInfo();
    $info['current_product_id'] = Mage::registry('current_product')->getId();
    $info['customer_id'] = Mage::getSingleton('customer/session')->getCustomerId();
    return $info;
}

【问题讨论】:

  • 什么版本的 Magento 以及您使用的 PFC 模块是什么?
  • magento 1.4 并在自定义模块中实现了 FPC
  • 嗯,也许它在自定义模块中?但我们需要更多。
  • 它是默认的magento块缓存。从这里实现。inchoo.net/magento/magento-block-caching
  • @Ronn0 - 请检查更新后的问题

标签: magento magento-1.4


【解决方案1】:

在这种情况下,您需要从getCacheKey 方法返回一个自定义值,例如:

public function getCacheKey(){
    if (Mage::getSingleton('customer/session')->getCustomerId() == '') {
        return 'custom_cache_key_not_loggedin';
    } else {
        return 'custom_cache_key_' . Mage::getSingleton('customer/session')->getCustomerId();
    }
}

但请记住,如果您的 FPC(全页缓存)已启用,这将不会产生任何影响。因为完整页面缓存不是您所要求的问题。

如果我在你身边,我该怎么办?

在您的情况下,我希望在用户登录时跳过缓存特定(用户)块。

【讨论】:

  • 感谢您的回答,但我需要在另一个函数 getOptionHML() 中获取客户会话 ID
  • 好吧,如果您以正确的方式阅读它,您会发现您实现cachinig 的方式是不正确的。所以无论你在哪里需要价值都没有关系。这是一个改进缓存方式和背后逻辑的问题。
猜你喜欢
  • 1970-01-01
  • 2021-01-22
  • 2022-08-18
  • 1970-01-01
  • 2017-11-12
  • 2015-04-29
  • 2013-12-20
  • 2014-12-05
  • 1970-01-01
相关资源
最近更新 更多