@TONEGOLF71
@SPACE48ERS
#MAGETITANS
MAGENTO CACHE
TAGS AND DEBUGGING
!
Tony Brown
Technical Director @ Space 48
Slide 2
Slide 2 text
@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?
Slide 3
Slide 3 text
@TONEGOLF71
@SPACE48ERS
#MAGETITANS
Many types of caching
• Browser caching
• Reverse proxy (Varnish, NGINX)
• Opcode Cache (APC, OPcache)
• Application cache (Magento)
• Plus many more…
Slide 4
Slide 4 text
@TONEGOLF71
@SPACE48ERS
#MAGETITANS
Magento Cache
Slide 5
Slide 5 text
@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)
@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
@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?!
Slide 10
Slide 10 text
@TONEGOLF71
@SPACE48ERS
#MAGETITANS
Diagnose the issue
Tags cleared on
product save
Breakpoint in Mage_Core_Model_Cache on clean()
Slide 11
Slide 11 text
@TONEGOLF71
@SPACE48ERS
#MAGETITANS
Diagnose the issue
Tags
associated on
product view
Breakpoint in
Mage_Core_Model_Cache
on save()
Slide 12
Slide 12 text
@TONEGOLF71
@SPACE48ERS
#MAGETITANS
WTF?
Slide 13
Slide 13 text
@TONEGOLF71
@SPACE48ERS
#MAGETITANS
Diagnose the issue
Tags saved on
product view
Breakpoint in
Mage_Core_Model_Cache
on save()
Slide 14
Slide 14 text
@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!!!
Slide 15
Slide 15 text
@TONEGOLF71
@SPACE48ERS
#MAGETITANS
But Why?
Slide 16
Slide 16 text
@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??
Slide 17
Slide 17 text
@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!!!
Slide 18
Slide 18 text
@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
Slide 19
Slide 19 text
@TONEGOLF71
@SPACE48ERS
#MAGETITANS
In short…
• Use Xdebug to check out what your cache tags are
doing!