Full Page Cache : Flow applyWithoutApp() in Magento
1] How to work/flow applyWithoutApp() in magento? (Magento ver. 1.13.0.2)Class : Enterprise_PageCache_Model_Container_Abstract
/** Generate placeholder content before application was initialized and apply to page content if possible
* @param string $content
* @return bool **/
public function applyWithoutApp(&$content)
[Line No : 1]
{
$cacheId = $this->_getCacheId(); [Line No : 2]
if ($cacheId === false) {
$this->_applyToContent($content, ”); [Line No : 3]
return true;
}
$block = $this->_loadCache($cacheId);[Line No : 4]
if ($block === false) {
return false;
}
$block = Enterprise_PageCache_Helper_Url::replaceUenc($block); [Line No : 5]
$this->_applyToContent($content, $block);[Line No : 6]
return true;
}
Purpose of function applyWithoutApp() :
This function generate placeholder content before application was initialized and apply to page content if possible
applyWithoutApp($content) function loads page without initialize application, it means that loads page using full page cache processor and check placeholder for a block in it. Using placeholder the processor identify the container class for dynamic block.
The container then load the dynamic block contents from the block cache, using the cache key by using
$cacheId = $this->_getCacheId();
If a cache key is already present, the container class replaces the placeholder in the $content with the cached block output.
Stack for applyWithoutApp() :
#1
Enterprise_PageCache_Model_Container_Welcome[Enterprise_PageCache_Model_Container_Abstract]
#000000005c8265da000000003e10428d#->applyWithoutApp(‘
#2
Enterprise_PageCache_Model_Processor#000000005c8265c5000000003e10428d#->_processContainers(‘
#3
Enterprise_PageCache_Model_Processor#000000005c8265c5000000003e10428d#->_processContent(‘
#4
Enterprise_PageCache_Model_Processor#000000005c8265c5000000003e10428d#->extractContent(false)
called at [app\code\core\Mage\Core\Model\Cache.php:687]
#5
Mage_Core_Model_Cache#000000005c8265c1000000003e10428d#->processRequest()
called at [app\code\core\Mage\Core\Model\App.php:340]
#6
Mage_Core_Model_App#000000005c8265ce000000003e10428d#->run(array(‘scope_code’ => ”, ‘scope_type’ => ‘store’, ‘options’ => array())) called at [app\Mage.php:683]
#7
Mage::run(”, ‘store’) called at [index.php:87]
Sample data for function : applyWithoutApp() for container welcome
[Line No : 1]
$content =
some content……….
some content……………………………..
Some Content….
[Line No : 2]
$cacheId = CONTAINER_WELCOME_869f0fe9239266819f6e4d38252b4cb2
[Line No : 3]
Default welcome msg!
[Line No : 4]
Default welcome msg!
[Line No : 5]
$block = Enterprise_PageCache_Helper_Url::replaceUenc($block);
class Enterprise_PageCache_Helper_Url
/**
* Calculate UENC parameter value and replace it
*
* @param string $content
* @return string
*/
public static function replaceUenc($content)
{
$urlHelper = new Mage_Core_Helper_Url;
$search = ‘/\/(‘ . Mage_Core_Controller_Front_Action
::PARAM_NAME_URL_ENCODED . ‘)\/[^\/]*\//’;
$replace = ‘/$1/’ . $urlHelper->getEncodedUrl() . ‘/’;
$content = preg_replace($search, $replace, $content);
return $content;
}
The above function removes the container pattern and give HTML of welcome container
Default welcome Msg!