diff --git a/app/code/core/Mage/Core/Model/Layout/Update.php b/app/code/core/Mage/Core/Model/Layout/Update.php index 3c4809116e5..d2fc6598acf 100644 --- a/app/code/core/Mage/Core/Model/Layout/Update.php +++ b/app/code/core/Mage/Core/Model/Layout/Update.php @@ -32,6 +32,11 @@ class Mage_Core_Model_Layout_Update */ const LAYOUT_GENERAL_CACHE_TAG = 'LAYOUT_GENERAL_CACHE_TAG'; + /** + * Prefix used for actual XML storage (unprefixed is just the sha1 hash) + */ + const XML_KEY_PREFIX = 'XML_'; + /** * Layout Update Simplexml Element Class Name * @@ -182,6 +187,13 @@ public function loadCache() return false; } + // The cache key is just a hash of the real content to de-duplicate the often large XML strings + if (strlen($result) === 40) { // sha1 + if (!$result = Mage::app()->loadCache(self::XML_KEY_PREFIX . $result)) { + return false; + } + } + $this->addUpdate($result); return true; @@ -194,8 +206,17 @@ public function saveCache() } $str = $this->asString(); $tags = $this->getHandles(); + + // Cache key is sha1 hash of actual XML string + $hash = sha1($str); $tags[] = self::LAYOUT_GENERAL_CACHE_TAG; - return Mage::app()->saveCache($str, $this->getCacheId(), $tags, null); + Mage::app()->saveCache($hash, $this->getCacheId(), $tags, null); + + // Only save actual XML to cache if it doesn't already exist + if ( ! Mage::app()->getCache()->test(self::XML_KEY_PREFIX . $hash)) { + Mage::app()->saveCache($str, self::XML_KEY_PREFIX . $hash, $tags, null); + } + return TRUE; } /**