Optimus Cache Prime
Optimus Cache Prime (OCP) is a smart cache preloader for websites with XML sitemaps. It crawls all URLs in a given sitemap so the web server builds cached versions of the pages before visitors or search engine spiders arrive.
Since Google began penalizing websites with long response times in their rankings, serving all of your pages quickly has become more important than ever. Optimus Cache Prime helps you do that by making sure your cache — be it an in-memory cache like memcached or APC, or a flat file cache like WP Super Cache or W3 Total Cache — is primed so random requests are served lightning fast.
|Linux (32-bit)||2.6 – 2012-04-23||ocp-2.6-i386.tar.gz||1.2 MB|
|Linux (64-bit)||2.7 – 2014-12-27||ocp-2.7-amd64.tar.gz||1.8 MB|
|Windows (64-bit)||2.7 – 2014-12-27||ocp-2.7.zip||1.7 MB|
|Other platforms||1.1 – 2010-12-20||Legacy Python Version|
||Prime all URLs in a local sitemap|
||Prime all URLs in a remote sitemap|
||Prime all URLs in a remote sitemap, priming up to 10 URLs at once|
||Prime each URL in a remote sitemap only if a cached version of the page (<-l path>/<page name>/index.html) doesn’t already exist|
||Prime each URL in a remote sitemap only if a cached version of the page (<-l path>/<page name>/_index.html) doesn’t already exist|
||Prime each URL in a remote sitemap only if a cached version of the page doesn’t already exist, and stop after priming 20 (uncached) pages|
Don’t prime, but run
./ocp without any parameters to get an overview and explanation of all available options.
- Cache checking
- Nested sitemap/sitemap index support
- Priming an arbitrary number of URLs simultaneously
- HTTP KeepAlive and session re-use (when applicable)
- Warns if the pages in your sitemap don’t load, return a 404 Not Found status, etc.
Customizable User-Agent (
Doubles as a general-purpose (nested) sitemap parser for use with external commands (
Run OCP on any machine specifying a target sitemap — e.g. one that links to all of your pages, or one that lists only the high-priority pages — and Optimus primes the links therein.
If run locally on your web server, OCP can probe your static file cache before making any requests to your web server, reducing the amount of requests and redundant log messages drastically. Pages are only crawled if they aren’t already cached.
OCP checks up to 10,000 pages per second with local mode enabled if the cache is mostly primed from previous runs. Local mode was designed for use with W3 Total Cache and WP Super Cache for WordPress, but will work with any system that uses a URL-relative flat file cache (i.e. /about/ is cached as e.g. ‘about’ or ‘about/index.html’ on the disk.)
Q: How do I install and use OCP?
A: On Windows, download and extract the zip file above, then run ocp.exe either through a command prompt, or by right-clicking ocp.exe, making a shortcut, changing the parameters for that shortcut (in Properties) to e.g.:
“D:.exe” -c 10 http://mysite.com/sitemap.xml, and then running it. On Linux, copy the link for your architecture above, then run
curl -s <link> | tar xvz, and you’re good to go.
cd ocp, and run e.g.
./ocp -c 10 http://mysite.com/sitemap.xml.
Q: How do I make an XML sitemap?
A: You can use a sitemap generator like OCP’s brother Optimus Sitemap Generator, or online/addon versions like XML-Sitemaps.com and Arne Brachhold’s XML Sitemap Generator (for WordPress.) You can also make one manually — here’s an example.
Q: Do I need to have WordPress, W3 Total Cache, WP Super Cache, memcached, … to use OCP?
A: No. All you need is an XML sitemap. To use Local mode you need something which stores its cached pages with file/directory names that are relative to the original URLs. (Both W3 Total Cache and WP Super Cache do just that.)
Q: Can you demonstrate how to use Local mode?
A: You can run
ocp with parameters like:
WordPress with W3 Total Cache:
./ocp -l /var/www/patrickmylund.com/wp-content/w3tc/pgcache -ls _index.html /var/www/patrickmylund.com/sitemap.xml
Translation: Look for already-cached files in /var/www/patrickmylund.com/wp-content/w3tc/pgcache, where the cached file for e.g. https://patrickmn.com/about/ is <path>/about/_index.html
WordPress with WP Super Cache:
./ocp -l /var/www/patrickmylund.com/wp-content/cache/supercache/patrickmylund.com /var/www/patrickmylund.com/sitemap.xml
Translation: Look for already-cached files in /var/www/patrickmylund.com/wp-content/cache/supercache/patrickmylund.com, where the cached file for e.g. https://patrickmn.com/about/ is <path>/about/index.html
Q: How do I know if Local mode is working?
A: You shouldn’t see any requests from “Optimus Cache Prime” in your web server’s access log, and runs subsequent to the first should complete in less than a second.
Q: How do I preload the cache regularly?
A: The easiest way is to set up a cron job. On most Linux distributions you can do this by adding a cron entry using
crontab -e. The entry can be e.g.
/5 * * * /home/patrick/ocp https://patrickmn.com/sitemap.xml, which will run OCP every five minutes. For more information, see Ubuntu’s Cron Howto.
(Note that Cron’s environment/path is very minimal, and you might need to use full paths to your commands.)
Q: How can I make sure only one OCP process runs at the same time?
A: If you’d like to run OCP e.g. every minute via cron, but don’t want several copies of the program to launch if the priming process is taking a while, you can use one.sh to launch OCP.
Here are the highlights from the past releases to the current:
|2.7 – 2014-12-27||
|2.6 – 2012-04-23||
|2.5 – 2012-02-11||
|2.4 - 2011-12-22||
|2.3 - 2011-11-23||
|2.2 - 2011-11-17||
|2.1 - 2011-11-17||
|2.0 - 2011-08-06||
|1.1 - 2010-12-20||
|1.0 - 2010-11-12||
Optimus Cache Prime (OCP) is released under the MIT license.