/** * Prepare response body before caching * * @param Zend_Controller_Response_Http $response * @return string */ public function prepareContent(Zend_Controller_Response_Http $response) { /** @var Enterprise_PageCache_Model_Processor */ $processor = Mage::getSingleton('enterprise_pagecache/processor'); $countLimit = Mage::getStoreConfig(Mage_Reports_Block_Product_Viewed::XML_PATH_RECENTLY_VIEWED_COUNT); // save recently viewed product count limit $cacheId = $processor->getRecentlyViewedCountCacheId(); if (!Mage::app()->getCache()->test($cacheId)) { Mage::app()->saveCache($countLimit, $cacheId); } // save current product id $product = Mage::registry('current_product'); if ($product) { $cacheId = $processor->getRequestCacheId() . '_current_product_id'; Mage::app()->saveCache($product->getId(), $cacheId); Enterprise_PageCache_Model_Cookie::registerViewedProducts($product->getId(), $countLimit); } return parent::prepareContent($response); }
/** * Prepare response body before caching * * @param Zend_Controller_Response_Http $response * @return string */ public function prepareContent(Zend_Controller_Response_Http $response) { $cacheInstance = Enterprise_PageCache_Model_Cache::getCacheInstance(); /** @var Enterprise_PageCache_Model_Processor */ $processor = Mage::getSingleton('enterprise_pagecache/processor'); $countLimit = Mage::getStoreConfig(Mage_Reports_Block_Product_Viewed::XML_PATH_RECENTLY_VIEWED_COUNT); // save recently viewed product count limit $cacheId = $processor->getRecentlyViewedCountCacheId(); if (!$cacheInstance->getFrontend()->test($cacheId)) { $cacheInstance->save($countLimit, $cacheId, array(Enterprise_PageCache_Model_Processor::CACHE_TAG)); } // save current product id $product = Mage::registry('current_product'); if ($product) { $cacheId = $processor->getRequestCacheId() . '_current_product_id'; $cacheInstance->save($product->getId(), $cacheId, array(Enterprise_PageCache_Model_Processor::CACHE_TAG)); $processor->setMetadata(self::METADATA_PRODUCT_ID, $product->getId()); Enterprise_PageCache_Model_Cookie::registerViewedProducts($product->getId(), $countLimit); } return parent::prepareContent($response); }
/** * Remove customer cookie * * @param Varien_Event_Observer $observer * @return Enterprise_PageCache_Model_Observer */ public function customerLogout(Varien_Event_Observer $observer) { if (!$this->isCacheEnabled()) { return $this; } $this->_getCookie()->updateCustomerCookies(); if (!$this->_getCookie()->get(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER)) { $this->_getCookie()->delete(Enterprise_PageCache_Model_Cookie::COOKIE_RECENTLY_COMPARED); $this->_getCookie()->delete(Enterprise_PageCache_Model_Cookie::COOKIE_COMPARE_LIST); Enterprise_PageCache_Model_Cookie::registerViewedProducts(array(), 0, false); } return $this; }
/** * Get page content from cache storage * * @param string $content * @return string|false */ public function extractContent($content) { $cacheInstance = Enterprise_PageCache_Model_Cache::getCacheInstance(); /* * Apply design change */ $designChange = $cacheInstance->load($this->getRequestCacheId() . self::DESIGN_CHANGE_CACHE_SUFFIX); if ($designChange) { $designChange = unserialize($designChange); if (is_array($designChange) && isset($designChange['package']) && isset($designChange['theme'])) { $designPackage = Mage::getSingleton('core/design_package'); $designPackage->setPackageName($designChange['package'])->setTheme($designChange['theme']); } } if (!$this->_designExceptionExistsInCache) { //no design exception value - error //must be at least empty value return false; } if (!$content && $this->isAllowed()) { $subprocessorClass = $this->getMetadata('cache_subprocessor'); if (!$subprocessorClass) { return $content; } /* * @var Enterprise_PageCache_Model_Processor_Default */ $subprocessor = new $subprocessorClass(); $this->setSubprocessor($subprocessor); $cacheId = $this->prepareCacheId($subprocessor->getPageIdWithoutApp($this)); $content = $cacheInstance->load($cacheId); if ($content) { if (function_exists('gzuncompress')) { $content = gzuncompress($content); } $content = $this->_processContent($content); // restore response headers $responseHeaders = $this->getMetadata('response_headers'); $response = Mage::app()->getResponse(); if (is_array($responseHeaders)) { $response->clearHeaders(); foreach ($responseHeaders as $header) { $response->setHeader($header['name'], $header['value'], $header['replace']); } } // renew recently viewed products $productId = $cacheInstance->load($this->getRequestCacheId() . '_current_product_id'); $countLimit = $cacheInstance->load($this->getRecentlyViewedCountCacheId()); if ($productId && $countLimit) { Enterprise_PageCache_Model_Cookie::registerViewedProducts($productId, $countLimit); } } } return $content; }
/** * Set cookie for logged in customer * * @param Varien_Event_Observer $observer */ public function customerLogin(Varien_Event_Observer $observer) { if (!$this->isCacheEnabled()) { return $this; } $this->_getCookie()->updateCustomerCookies(); // update customer viewed products index try { $productIds = $this->_getCookie()->get(Enterprise_PageCache_Model_Container_Viewedproducts::COOKIE_NAME); if ($productIds) { $productIds = explode(',', $productIds); Mage::getModel('reports/product_index_viewed')->registerIds($productIds); } } catch (Exception $e) { Mage::logException($e); } // renew customer viewed product ids cookie $countLimit = Mage::getStoreConfig(Mage_Reports_Block_Product_Viewed::XML_PATH_RECENTLY_VIEWED_COUNT); $collection = Mage::getResourceModel('reports/product_index_viewed_collection')->addIndexFilter()->setAddedAtOrder()->setPageSize($countLimit)->setCurPage(1); Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($collection); $productIds = $collection->load()->getLoadedIds(); $productIds = implode(',', $productIds); Enterprise_PageCache_Model_Cookie::registerViewedProducts($productIds, $countLimit, false); return $this; }
/** * Get page content from cache storage * * @param string $content * @return string | false */ public function extractContent($content) { Mage::app()->getRequest(); if (!$content && $this->isAllowed()) { $subprocessorClass = $this->getMetadata('cache_subprocessor'); if (!$subprocessorClass) { return $content; } /* * @var Enterprise_PageCache_Model_Processor_Default */ $subprocessor = new $subprocessorClass(); $cacheId = $this->prepareCacheId($subprocessor->getPageIdWithoutApp($this)); $content = Mage::app()->loadCache($cacheId); if ($content) { if (function_exists('gzuncompress')) { $content = gzuncompress($content); } $content = $this->_processContent($content); // renew recently viewed products $productId = Mage::app()->loadCache($this->getRequestCacheId() . '_current_product_id'); $countLimit = Mage::app()->loadCache($this->getRecentlyViewedCountCacheId()); if ($productId && $countLimit) { Enterprise_PageCache_Model_Cookie::registerViewedProducts($productId, $countLimit); } } } return $content; }