Neptune Web, Inc. logo

Enabling Magento Enterprise Full Page Cache on your Store Home Page

Assuming you are running Magento 1.8 Enterprise, you may have noticed that the home page does not cache by default, even though System -> Configuration -> Cache Management -> Page Cache is set.

Only catalog and product pages make use of the full page cache by default.*

*Update: On a second Magento installation, with different modules installed, this was not true. On the installation where this problem occurred, it appears the core module handles the homepage request.

Run the find command to see which full pages are cached (REQEST - yes misspelled) indicates the page was cached.

find var/cache -name "*REQEST_*" -print
(UPDATE: in later versions of Magento Enterprise - 1.11+, var/full_page_cache is the default location for cache files)

In the file app/code/core/Enterprise/PageCache/etc/config.xml, you will see the section which you can configure to get other pages cached. The relevant section is as follows:


<cache>
<requests>
<cms>enterprise_pagecache/processor_default</cms>
<catalog><category><view>...</view></category></catalog>
<catalog><product><view>...</view></product></catalog>
</requests>
</cache>

Add the following line between the <requests></requests> tags:

<core>
<index>enterprise_pagecache/processor_default</index>
</core>
<requests><catalog>re></catalog></requests>

However, this still isn't going to work. There is a bug within Magento, which returns a "1" (yes, the number 1) as a result of:


$request->getModuleName()

(I didn't have time to research the origin of this bug, as mentioned above it may have been a module we installed). So, add a single code line to the file:

app/code/core/Enterprise/PageCache/Model/
Processor.php (around line 320)
... $module = $request->getModuleName(); // existing code
if ($module == '1') { $module = 'core'; } 
// THE ABOVE LINE IS THE FIX TO GET THIS CACHE TO 
// WORK ON HOMEPAGE.
if (isset($configuration[$module])) {    //existing code
//  etc..

A file over-ride (clone file and directory structure in app/code/local) would probably be best here.

Once you've made those changes, clear your config cache, and the homepage will now cache.

This small change can have a dramatic effect on the performance of your web site, since a good percentage of people enter the site from the home page and never add anything to the cart (which invalidates the cache*). Therefore, the entire session can make use of the full page cache.

* See app/code/core/Enterprise/PageCache/Model/Processor.php isAllowed function (modified with comments below) to see what other conditions invalidate the cache for the user. E.g. the request must NOT have the cookie NO_CACHE set (that cookie is set when a session is started - an item is added to cart), it must not be secure (https), and it must not have the GET variable no_cache set. Adding logging below is a good idea to see if your page is caching.

Assuming you're on fast hardware a 200-400ms page request time means you're making use of the page cache. 800-1200ms hits mean your probably not making use of the page cache.

public function isAllowed()
    {
        if (!$this->_requestId) {
        error_log("page cache not used because NO REQUEST for request " . $_SERVER["PATH_INFO"]);
            return false;
        }
        if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
                error_log("page cache not used because sECURE for request " . $_SERVER["PATH_INFO"]);
            return false;
        }
        if (isset($_COOKIE['NO_CACHE'])) {
                error_log("page cache not used because cache cookie set for request " . $_SERVER["PATH_INFO"]);
            return false;
        }
        if (isset($_GET['no_cache'])) {
                error_log("page cache not used because of cache GETVAR set for request " . $_SERVER["PATH_INFO"]);
            return false;
        }
        return true;
    }

Neptune Web is a full-service Boston-area interactive web and digital marketing agency with expertise in Website Design, Web Development, Digital Marketing Strategy and Execution.

We look forward to your comments and would be most happy to address and help solve any Digital Marketing or Website Design & Development challenges you may have.

comments powered by Disqus