3

There are new problems with static blocks in 1.9.2

there is one more problem with CMS blocks caching, that is not fixed.

If you are using secure urls and {{media}} tags in your CMS blocks, you will receive "Insecure content warning" message from browser, as Magento serves insecure links from cache.

To resolve it, you need to add one more cache info tag, as

(int)Mage::app()->getStore()->isCurrentlySecure(),

Does anyone know where to add this code-snippet?

KNOWN BUG: http://www.magentocommerce.com/bug-tracking/issue/index/id/870

3

By default, Magento CMS Block will not be cached. So it would be nice if we cache CMS static blocks. This is what this extension does (one of my free extension). Feel free to use it.

Basically this extension listens to the event core_block_abstract_to_html_before and enable cacheing for CMS Blocks. This is what observer does

public function enableCmsBlockCaching(Varien_Event_Observer $observer)
{
    $block = $observer->getBlock();

    if ($block instanceof Mage_Cms_Block_Widget_Block
        || $block instanceof Mage_Cms_Block_Block
    ) {

        $cacheKeyData = array(
            Mage_Cms_Model_Block::CACHE_TAG,
            $block->getBlockId(),
            Mage::app()->getStore()->getId(),
            intval(Mage::app()->getStore()->isCurrentlySecure())
        );
        $block->setCacheKey(implode('_', $cacheKeyData));

        $block->setCacheTags(array(
            Mage_Core_Model_Store::CACHE_TAG,
            Mage_Cms_Model_Block::CACHE_TAG,
            (string)$block->getBlockId()
        ));

        $block->setCacheLifetime(false);
    }
    return $this;
}

What this Observer Does : It first retrieve each static blocks from the layout and then apply cache. The unique cache key is generated for each static blocks. This unique key is made up of

  • CMS cache tag
  • Static Block Identifier
  • Current Store Used
  • Secure Url or Not

So the cache key will be unique in most of the circumstances and you already saw that for secure and not secure urls, cache key will be different. That's it.

Note : As @AdershKatri pointed out, you should also have look on this thread

If you have any doubts, let me know.

  • I have tested this and it does resolve the problem, but will this result in Magento caching the static block data twice? Once by the (buggy) core code, and then again by your observer? – paj Jul 21 '15 at 10:31
  • 1
    nope. as you can see, the extension is setting some values. Nothing more nothing less. Later magento will use this cache values to generate cache.. So no twice cacheing. – Rajeev K Tomy Jul 21 '15 at 10:56
  • Ok, I understand that now, good solution. Can I suggest you add a modman installer for the module to your git project. – paj Jul 21 '15 at 12:08
  • it would be greatly appreciated if you can make a pull request for that.. – Rajeev K Tomy Jul 21 '15 at 12:11
  • pull request done. – paj Jul 21 '15 at 12:46
2

1.9.2 introduced caching to cms/block blocks, seen here

class Mage_Cms_Block_Block extends Mage_Core_Block_Abstract
{
    protected function _construct()
    {
        /*
        * setting cache to save the cms block
        */
        $this->setCacheTags(array(Mage_Cms_Model_Block::CACHE_TAG));
        $this->setCacheLifetime(false);
    }
    // ...
}

The edit you're quoting is suggesting to add the fact the request is secure to differentiate one cache from the other. This means modifying/extending Mage_Cms_Block_Block using the getCacheKeyInfo() method with something like

class Mage_Cms_Block_Block extends Mage_Core_Block_Abstract
{
    // ...
    public function getCacheKeyInfo()
    {
        if ($this->getBlockId()) {
            return array(
                Mage_Cms_Model_Block::CACHE_TAG,
                Mage::app()->getStore()->getId(),
                $this->getBlockId(),
                (int) Mage::app()->getStore()->isCurrentlySecure()
            );
        } else {
            return parent::getCacheKeyInfo();
        }
    }
    // ...
}
0

The cms page content will get filter by following file.

app/code/core/Mage/Core/Model/Email/Template/Filter.php

Mage_Core_Model_Email_Template_Filter::mediaDirective

You can make copy of the file and paste it in local codepool and do you changes.

0

A temporary solution while the bug is being fixed is to go system>cache management and tick the 'Blocks HTML output' and in actions 'disable'. You can enable when Magento has fixed the issue.

0

This problem has been fixed in Magento 1.9.2.1 released 4th August 2015.

http://www.magentocommerce.com/bug-tracking/issue/index/id/870

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.