Sankar Subburaj
Sankar Subburaj

Reputation: 5042

Explain Magento caching system

Could anyone explain about the Magento Caching system & how cache module works in Magento?

Upvotes: 10

Views: 11680

Answers (2)

ShaunOReilly
ShaunOReilly

Reputation: 2206

Read more about it here: http://www.magentocommerce.com/wiki/modules_reference/english/mage_adminhtml/system_cache/index

or http://docs.magento.com/m1/ce/user_guide/system-operations/cache-management.html?Highlight=system%20cache

and for full page cahing:

http://docs.magento.com/m1/ce/user_guide/system-operations/cache-page-external.html?Highlight=system%20cache

From this link:

This screen will allow you to manage cache settings for different internal Magento aspects. To access the Cache Management screen (System > Cache Management)

Cache Control

In this fieldset you are presented with checkboxes, which, if checked, will enable cache for each aspect as described below.

During developing, i.e. changing files or database directly, disable all cache to avoid undefined behaviour.

After extension upgrade, installation or uninstallation, refresh all cache.

During moving Magento to another server, cached config.xml and local.xml are causing problems and have effectively locked you out of the admin panel. Find /app/etc/use_cache.ser and rename it to kill all caching manually and force reload of these files.

All Cache This select box is a convenience feature to apply an action to all checkboxes.

No Change - No action will be taken that will affect all aspects. Refresh - All cache will be cleaned, but all enabled aspects will remain enabled. Disable - Disable all cache. Enable - Enable all cache.

Currently the caching is implemented in core components mostly.

  • Configuration Here we cache merged config.xml files from app/etc/, all the modules and custom configuration saved in the database.

  • Layouts Compiling layout updates from app/design/[package]/[theme]/layout/*.xml files into layouts cache for each page

  • Blocks HTML output Every block can be cacheable by setting cache_lifetime and cache_key. This could involve pretty sophisticated logic to avoid representation inconsistencies between different blocks. Currently only admin top navigation block is cached.

  • EAV types and attributes EAV (entity-attribute-value model) requires configuration to be loaded from database. To speed up the initialization we cache this configuration.

  • Translations Every module and every theme can supply it’s own translation files (currently .csv) We cache all of them to avoid wasting time on recompilation.

You could play with setCacheLifetime and setCacheKey for blocks that display product data and see how it works for you

Upvotes: 13

davidselo
davidselo

Reputation: 1325

You can cache a block in magento rewriting a bunch of methods.

protected function _construct()
    {
        $this->addData(array(
            'cache_lifetime'    => 900,
            'cache_tags'        => array(Mage_Catalog_Model_Product::CACHE_TAG),
            'cache_key'            => $this->getCacheKey()
        ));
        // cache_lifetime=> time to cached the block
        // cache_tags=> type of the cache
        // cache_key => the key of the cache
    } 

public function getCacheKey()
    {

    }
...

i recommend you see a block for example in the core. For example: Mage_Poll_Block_Poll

later you should enable profiler and see if the block are cached or not. You can see more information in this link http://inchoo.net/ecommerce/magento/magento-block-caching/

Upvotes: 6

Related Questions