$30 off During Our Annual Pro Sale. View Details »

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
    MAGENTO CACHE
    TAGS AND DEBUGGING
    !
    Tony Brown
    Technical Director @ Space 48

    View Slide

  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?

    View Slide

  3. @TONEGOLF71
    @SPACE48ERS
    #MAGETITANS
    Many types of caching
    • Browser caching
    • Reverse proxy (Varnish, NGINX)
    • Opcode Cache (APC, OPcache)
    • Application cache (Magento)
    • Plus many more…

    View Slide

  4. @TONEGOLF71
    @SPACE48ERS
    #MAGETITANS
    Magento Cache

    View Slide

  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)

    View Slide

  6. @TONEGOLF71
    @SPACE48ERS
    #MAGETITANS
    Magento Cache
    • Mage_Core_Model_Cache
    • save($value, $key, $tags = array(), $lifeTime=null)
    • load($key)
    • remove($key)
    • clean($tags = array())

    View Slide

  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

    View Slide

  8. @TONEGOLF71
    @SPACE48ERS
    #MAGETITANS
    Investigation tools
    • Mage::log()
    • Xdebug
    • Redis monitor

    View Slide

  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?!

    View Slide

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

    View Slide

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

    View Slide

  12. @TONEGOLF71
    @SPACE48ERS
    #MAGETITANS
    WTF?

    View Slide

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

    View Slide

  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!!!

    View Slide

  15. @TONEGOLF71
    @SPACE48ERS
    #MAGETITANS
    But Why?

    View Slide

  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??

    View Slide

  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!!!

    View Slide

  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

    View Slide

  19. @TONEGOLF71
    @SPACE48ERS
    #MAGETITANS
    In short…
    • Use Xdebug to check out what your cache tags are
    doing!

    View Slide

  20. @TONEGOLF71
    @SPACE48ERS
    #MAGETITANS
    THANKS!!
    [email protected]
    @tonegolf71

    View Slide