Session value not working when FPC cache enabled

938 views Asked by At

Session value not working in blocks when FPC cache enabled.How to handle the session value in cache enabled blocks.I have added the customer session id as below.How to get the customer id from cache in a block.

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;
}
1

There are 1 answers

2
Ronn0 On

In this case you need to return a custom value from the getCacheKey method, for example:

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();
    }
}

But please keep in mind this will not have any effect if your FPC (FULL page cache) is enabled. Because FULL page cache is not what you're asking for with your question.

What should I do if i where you?

What I would prefer in your situation is to skip caching specific (user) blocks when a user is loggedin.