/** * Process response body by specific request * * @param Zend_Controller_Request_Http $request * @param Zend_Controller_Response_Http $response * @return Enterprise_PageCache_Model_Processor */ public function processRequestResponse(Zend_Controller_Request_Http $request, Zend_Controller_Response_Http $response) { // we should add original path info tag as another way we can't drop some entities from cron job $this->addRequestTag(Enterprise_PageCache_Helper_Url::prepareRequestPathTag($request->getOriginalPathInfo())); $cacheInstance = Enterprise_PageCache_Model_Cache::getCacheInstance(); /** * Basic validation for request processing */ if ($this->canProcessRequest($request)) { $processor = $this->getRequestProcessor($request); if ($processor && $processor->allowCache($request)) { $this->setMetadata('cache_subprocessor', get_class($processor)); $cacheId = $this->prepareCacheId($processor->getPageIdInApp($this)); $content = $processor->prepareContent($response); /** * Replace all occurrences of session_id with unique marker */ Enterprise_PageCache_Helper_Url::replaceSid($content); Enterprise_PageCache_Helper_Form_Key::replaceFormKey($content); if (function_exists('gzcompress')) { $content = gzcompress($content); } $contentSize = strlen($content); $currentStorageSize = (int) $cacheInstance->load(self::CACHE_SIZE_KEY); if (Mage::getStoreConfig(Enterprise_PageCache_Model_Processor::XML_PATH_CACHE_DEBUG)) { $response->setBody(implode(', ', $this->getRequestTags()) . $response->getBody()); } $maxSizeInBytes = Mage::getStoreConfig(self::XML_PATH_CACHE_MAX_SIZE) * 1024 * 1024; if ($currentStorageSize >= $maxSizeInBytes) { Mage::app()->getCacheInstance()->invalidateType('full_page'); return $this; } $cacheInstance->save($content, $cacheId, $this->getRequestTags()); $cacheInstance->save($currentStorageSize + $contentSize, self::CACHE_SIZE_KEY, $this->getRequestTags()); /* * Save design change in cache */ $designChange = Mage::getSingleton('core/design'); if ($designChange->getData()) { $cacheInstance->save(serialize($designChange->getData()), $this->getRequestCacheId() . self::DESIGN_CHANGE_CACHE_SUFFIX, $this->getRequestTags()); } // save response headers $this->setMetadata('response_headers', $response->getHeaders()); // save original routing info $this->setMetadata('routing_aliases', Mage::app()->getRequest()->getAliases()); $this->setMetadata('routing_requested_route', Mage::app()->getRequest()->getRequestedRouteName()); $this->setMetadata('routing_requested_controller', Mage::app()->getRequest()->getRequestedControllerName()); $this->setMetadata('routing_requested_action', Mage::app()->getRequest()->getRequestedActionName()); $this->setMetadata('sid_cookie_name', Mage::getSingleton('core/session')->getSessionName()); Mage::dispatchEvent('pagecache_processor_metadata_before_save', array('processor' => $this)); $this->_saveMetadata(); } if (isset($_GET[Mage_Core_Model_Session_Abstract::SESSION_ID_QUERY_PARAM])) { Mage::getSingleton('enterprise_pagecache/cookie')->updateCustomerCookies(); Mage::getModel('enterprise_pagecache/observer')->updateCustomerProductIndex(); } } return $this; }
/** * Clear request path cache by tag * (used for redirects invalidation) * * @param Varien_Event_Observer $observer * @return $this */ public function clearRequestCacheByTag(Varien_Event_Observer $observer) { if (!$this->isCacheEnabled()) { return $this; } $redirect = $observer->getEvent()->getRedirect(); Enterprise_PageCache_Model_Cache::getCacheInstance()->clean(array(Enterprise_PageCache_Helper_Url::prepareRequestPathTag($redirect->getData('identifier')), Enterprise_PageCache_Helper_Url::prepareRequestPathTag($redirect->getData('target_path')), Enterprise_PageCache_Helper_Url::prepareRequestPathTag($redirect->getOrigData('identifier')), Enterprise_PageCache_Helper_Url::prepareRequestPathTag($redirect->getOrigData('target_path')))); return $this; }
/** * Clear request path cache by tag * (used for redirects invalidation) * * @param Varien_Event_Observer $observer * @return $this */ public function clearRequestCacheByTag(Varien_Event_Observer $observer) { $redirects = $observer->getEvent()->getRedirects(); foreach ($redirects as $redirect) { Enterprise_PageCache_Model_Cache::getCacheInstance()->clean(array(Enterprise_PageCache_Helper_Url::prepareRequestPathTag($redirect['identifier']))); } return $this; }