Magento Cache Tags and Debugging

4ef59bf6e60aa9e2bd50126f6f332ff9?s=47 Tony Brown
November 01, 2014

Magento Cache Tags and Debugging

4ef59bf6e60aa9e2bd50126f6f332ff9?s=128

Tony Brown

November 01, 2014
Tweet

Transcript

  1. @TONEGOLF71 @SPACE48ERS #MAGETITANS MAGENTO CACHE TAGS AND DEBUGGING ! Tony

    Brown Technical Director @ Space 48
  2. @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?
  3. @TONEGOLF71 @SPACE48ERS #MAGETITANS Many types of caching • Browser caching

    • Reverse proxy (Varnish, NGINX) • Opcode Cache (APC, OPcache) • Application cache (Magento) • Plus many more…
  4. @TONEGOLF71 @SPACE48ERS #MAGETITANS Magento Cache

  5. @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)
  6. @TONEGOLF71 @SPACE48ERS #MAGETITANS Magento Cache • Mage_Core_Model_Cache • save($value, $key,

    $tags = array(), $lifeTime=null) • load($key) • remove($key) • clean($tags = array())
  7. @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
  8. @TONEGOLF71 @SPACE48ERS #MAGETITANS Investigation tools • Mage::log() • Xdebug •

    Redis monitor
  9. @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?!
  10. @TONEGOLF71 @SPACE48ERS #MAGETITANS Diagnose the issue Tags cleared on product

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

    view Breakpoint in Mage_Core_Model_Cache on save()
  12. @TONEGOLF71 @SPACE48ERS #MAGETITANS WTF?

  13. @TONEGOLF71 @SPACE48ERS #MAGETITANS Diagnose the issue Tags saved on product

    view Breakpoint in Mage_Core_Model_Cache on save()
  14. @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!!!
  15. @TONEGOLF71 @SPACE48ERS #MAGETITANS But Why?

  16. @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??
  17. @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!!!
  18. @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
  19. @TONEGOLF71 @SPACE48ERS #MAGETITANS In short… • Use Xdebug to check

    out what your cache tags are doing!
  20. @TONEGOLF71 @SPACE48ERS #MAGETITANS THANKS!! tony@space48.com @tonegolf71