Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Magento Cache Tags and Debugging

Tony Brown
November 01, 2014

Magento Cache Tags and Debugging

Tony Brown

November 01, 2014
Tweet

Other Decks in Technology

Transcript

  1. @TONEGOLF71 @SPACE48ERS #MAGETITANS – Wikipedia “Caching is a component that

    transparently stores data so that future requests for that data can be served faster. ” What is caching?
  2. @TONEGOLF71 @SPACE48ERS #MAGETITANS Many types of caching • Browser caching

    • Reverse proxy (Varnish, NGINX) • Opcode Cache (APC, OPcache) • Application cache (Magento) • Plus many more…
  3. @TONEGOLF71 @SPACE48ERS #MAGETITANS Magento Cache • Key-value data store •

    Data can be tagged with meta data • By default is stored on the filesystem (/var) • Other storage backends can be used • We use Redis (thanks Colin Mollenhour)
  4. @TONEGOLF71 @SPACE48ERS #MAGETITANS Magento Cache • Mage_Core_Model_Cache • save($value, $key,

    $tags = array(), $lifeTime=null) • load($key) • remove($key) • clean($tags = array())
  5. @TONEGOLF71 @SPACE48ERS #MAGETITANS Problem • Inherited a Magento store •

    It had a full page caching (FPC) module in place • It was thought that the FPC was clearing too often
  6. @TONEGOLF71 @SPACE48ERS #MAGETITANS Replicate the issue • Small perceptible difference

    in cached versus uncached page loads. • We were told that the cache dropping seemed to coincide with catalog updates • We tested and yes, product saves would wipe the cache?!
  7. @TONEGOLF71 @SPACE48ERS #MAGETITANS Diagnose the issue Tags cleared on product

    save Breakpoint in Mage_Core_Model_Cache on clean()
  8. @TONEGOLF71 @SPACE48ERS #MAGETITANS Diagnose the issue Tags saved on product

    view Breakpoint in Mage_Core_Model_Cache on save()
  9. @TONEGOLF71 @SPACE48ERS #MAGETITANS Diagnose the issue • Eliminate as much

    as possible as quickly as possible • Go back to a core theme • Disable all non-core modules. • The culprit - A bespoke top-nav replacement module!!!
  10. @TONEGOLF71 @SPACE48ERS #MAGETITANS But why? • model_load_after observer in the

    FPC module • This collects tags for each model loaded via $object->getCacheIdTags() But WHY??
  11. @TONEGOLF71 @SPACE48ERS #MAGETITANS But why? • The bespoke menu navigation

    module uses Mage::getModel(‘catalog/category’)->load($Id) for each category • Therefore a tag for each category in the menu was added!!!
  12. @TONEGOLF71 @SPACE48ERS #MAGETITANS The solution? • Refactor the navigation menu

    to work in the same way as the core. • i.e use getCategories() from the category resource model