Caching WordPress for App Engine

Caching is one of the simplest ways to improve the performance of your WordPress site. There are two simple, easy to use caching techniques that you can leverage when hosting a WordPress site on App Engine.


App Engine has a zero configuration memcache service that can be used in conjunction with the memcached plugin, that reduces the number of database calls that are required to display a page. Batcache uses the memcache service to store and serve fully rendered pages. It has a number of tuning options that can be used to configure caching to not only reduce the time taken to serve pages, but the overall cost to run your site.

To get started using memcache and WordPress, download and install the plugins like this

$ wget
$ unzip -d /path/to/wordpress/wp-content/
$ wget
$ unzip -d /path/to/wordpress/wp-content/plugins/

Now edit your wp-config.php file and enable caching, and tune the batcache settings if you want.

define('WP_CACHE', true);
$batcache = [
    'seconds' => 0,
    'debug' => false,
    'max_age' => 60 * 30,  // 30 minutes.

Setting a large max_age value will dramatically reduce the database access of your application, at the price of clients potentially seeing stale pages. If you site has rarely changing content then this can be an effective way to reduce the overall cost of your application as it will reduce the usage of the CloudSQL database.

Now all that’s left is to use to push your application to production, and your WordPress site will start using the memcache service.You can use the admin console memcache viewer to see how many objects have been cached, how often there is a cache hit and flush the cache if required.

Static File Caching

When serving static files, App Engine will automatically add caching headers so that the resources can be cached by the users browser and any intermediate proxies. By default, the cache expiration time is 10 minutes. However, you can set this expiration time to a higher value if you have resources that rarely, if ever change.

The easiest way to do this is to set the default_expiration value in the app.yaml file of your WordPress site.

application: YOUR_PROJECT_ID
version: wp
runtime: php
api_version: 1

default_expiration: "1d"

Note: Be careful how you set the default expiration value. If you set a large expiration time like 365d then any changes to the content of the static resources will likely not be visible to users as the old content will still be cached in upstream proxies.

Using both of these techniques can result in vastly improved page load times for your site, combined with a reduction in the CloudSQL usage and therefor cost.