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.
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:
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().