How to use separate block caches for secure and insecure access to stores in Magento?

I use the Magento cache block for the top navigation block. The problem is that the block must generate some URLs for files in the skins directory that cannot be placed in css files, since the file names depend on the model model data.

Now, when I open magento using a secure connection (https: //), the navigation block is removed from the cache and sent to the browser, but with the http: // URLs, which leads to a warning in most browsers about insecure elements on the page.

I would like to have separate caches for secure and insecure connections. The navigation block extends the Mage_Catalog_Block_Navigation class and therefore has the following cache configuration:

  $this->addData(array( 'cache_lifetime' => false, 'cache_tags' => array(Mage_Catalog_Model_Category::CACHE_TAG, Mage_Core_Model_Store_Group::CACHE_TAG), )); 
+6
magento
source share
1 answer

Easier than I thought ...

I tried to override the getCacheKey() method by adding a flag with the current security status, but at first it was unsuccessful, but after a few cache chips, it seems to work now:

 public function getCacheKey() { $key = parent::getCacheKey(); $key .= Mage::app()->getStore()->isCurrentlySecure() ? '_S' : '_U'; return $key; } 
+4
source share

All Articles