Magento shopping cart item count + page caching
I have an item count indicator in the header of my Magento store, and when I have caching enabled on the site, it behaves jankily. Is i开发者_如何学JAVAt possible to disable caching for a particular .phtml template? I tried overriding the Mage_Page_Block_Html_Header
and adding $this->addData(array("cache_lifetime" => false))
to the _construct()
method, but that didn't seem to help. I would like the cart count to update based on the user obviously and there are bits of other template code in there that I'd like to run with every request as well.
what does "jankily" mean? in a default install of magento CE (i dunno about or if your using EE) this block isn't cached. if you can set a breakpoint on the getSummaryQty method and on the toHtml method in the abstract block that the header block extends (this function checks the cache) using a debugger eg netbeans with xdebug, you'll get to the heart of the matter faster than any other way.
You were probably on the right track with your override module, but there is a gotcha here. You would think that "cache_lifetime" => false
is the same as "do not cache". Not neccessarily so. Different sources report different findings;
"cache_lifetime" => 3600
:
cache until 3600 seconds old
"cache_lifetime" => null
: disable caching
(though Nick says "By setting this value to null, or omitting the argument, the value will remain in cache until removed.")
"cache_lifetime" => false
: no expiration, cache forever
(though Ivan@Inchoo states this makes it fallback to Zend_Cache default value of 7200 sec)
Yes I realize this is a couple years old and my answer is not finite, but others coming across this issue should be aware of these quirks. Also, maybe Chris Forette could post some code showing how this was solved in the end?
精彩评论