A (free) page cache for OpenCart


We’ve made the first release of our page level cache for opencart.

It’s a relatively simple module with an installer that makes a couple of changes to your main index.php file, and an admin panel to see stats, clear the cache, etc.

There’s more info on github…for opencart 1.5.x, see our pagecache repo, and for opencart 2.x, see our v2pagecache repo.

While a page cache doesn’t solve the root cause of performance problems,

it does provide a safety net for just about any type of code related performance issue.  Provided that you don’t use it as a crutch, page-level caching is a relatively safe way to make your site more responsive.

We use a customized version of this code on our commercial website (budgetneon.com), and have had great success with it thus far.

At a high level, this caching code works in 2 places within opencart’s main index.php file:

  • Near the top of the index.php file, before most of the opencart code ever loads and runs, it checks to see if a valid cached copy of the currently requested url exists.  If it does, the cache serves this from disk, then exits without ever running any opencart code, database queries, etc.  That makes it very fast for already cached pages.
  • At the bottom of the index.php file, just after a normal, not-previously-cached page has been served to the end user….we check and see if the request page SHOULD be cached.  If so, we write a copy of what was just sent to the end user into a disk file.

That second point does incur some overhead, but it’s reasonable when measured across the weight of the request without caching.  Our testing showed about a 15% bump in processing time the first time a page is requested.   Follow-on requests for the cached page then run much faster, and consume fewer resources.

The admin panel features:

  • The ability to enable or disable the cache, by adding/removing some code to your main index.php file.  (Make sure to have a backup copy of your index.php file, in case something goes wrong).
  • Statistics on the number of cache files, and the total disk space used, for both active cache files and expired ones.
  • Buttons to clear either all cached files, or just the expired ones.
  • A read-only view of the current settings.

Here’s a screenshot of the admin panel:

Click To Enlarge
Click To Enlarge

This page cache is released as open source, specifically using the Freebsd license, which places very few restrictions on it’s use, other than attribution.

The code is newly released, and only tested in our limited environments.  So, if you decide you want to use it, please be sure to test before rolling to production. There’s much more detail, as well as the code itself, at the github repository.

Update:  We ported this extension for the newly released Opencart 2.0 version.  Because the administrative interface is very different, we had to do it as a separate module, also available on github.

Also, since releasing this, it’s been downloaded by 200+ end users, all with a variety of environments.  We’ve been able to work with end users to get it working with a variety of php SAPI environments, including mod_php, fastcgi, and litespeed.  PHP 5.4 is highly recommended though.  Running under PHP 5.3 requires hacking up a replacement for http_response_code().

4 thoughts on “A (free) page cache for OpenCart

    1. Probably one of either…

      a) You’re logged into opencart or have items in your cart. We don’t cache pages for visitors in those two situations.

      b) You didn’t make the changes to index.php

  1. Hey;
    Been using pagecache & tried it for 3 different times. Manual & Auto with right configuration.
    Problem i face is -> My site is responsive and it caches mobile device pages along with desktop and tablet pages. Then the output on desktop gets torn. i mean the same as we see in mobile devices.

    How can we either get separate cache for small devices or my guess is wrong.
    If wrong then whats the reason which effect the cached pages once i access from mobile.

    Thanks in advance; I like pagecache so i need a way out possibly.


    1. We have no plans to support plugins that maintain a separate set of html for mobile devices. The cache does work fine with sites that implement mobile support with purely responsive techniques…for example, we run it on budgetneon.com.

      There are paid cache modules that support what you are asking for.

Leave a Reply

Your email address will not be published. Required fields are marked *

3 − = one