Home Magento Guide

Magento block caching

20 October 2009 No Comment

Recently we were working on speeding up parts of client site which had usual problem of slow page loading caused by complicated configurable products. To solve the problem we were experimenting with extending core Magento caching capabilities.

Magento has built in predifined system of block output caching. Its block abstract has Zend_Cache caching capabilities that can be modified for your own needs. I’m showing here an example of caching whole product view block, however this is just a specific example

of how things works, problems are different and requires different approach and solution.

I will start with some external reading and example itself. There is great article on Magento Wiki about this topic, along with category cache example on Magento forums.

With my Inchoo_BlockCaching.rar example module things should be little easier to understand.

Magento block caching depends of three things:
cache_lifetime => cache lifetime in seconds
cache_tags => cache type identifiers primarly used viagra lowest price for deleting right cache at the right time
cache_key => cache identyfier

You can simply inject this data into construtor of any Magento block

protected function _construct()
{
$this->addData(array(
"cache_lifetime" => 3600,
"cache_tags"     => array(Mage_Catalog_Model_Product::CACHE_TAG),
"cache_key"      => $this->getProduct()->getId(),
));
}

or if you need some conditional approach like i did in this example define equivalent functions

public function getCacheKey(){}
public function getCacheLifetime(){}
public function getCacheTags(){}

By Ivan Weiler from Inchoo.net

on line pharmacy



Related posts:

  1. Some custom Blocks to help you show products
  2. Bestseller module (with Toolbar!) – Magento 1.2.1
  3. Top 3 Solutions when your Magento Categories are not displaying
  4. What’s in a block? – Some Magento “basics”
  5. What’s in a block? – Some Magento "basics"

Comments are closed.