How to prevent Batcache page caching on Pressable

Category: TroubleShooting | Last modified: October 22, 2020

Pressable uses Batcache and Memcached to store and serve rendered pages. However, there are times where you might not want something cached, such as a specific page or cookie. This guide will help you exempt those items from Batcache.

Before making these modifications, you will want to make sure that the page is being served from Batcache. You can do this by checking the page headers in your browser’s development tools. If you see x-nananana: Batcache in the response headers, then you’ll know that the page is being served from Batcache.

Alternatively, you may load the source code of your page. For example: view-source:https://kb.pressable.com/. You should see an HTML comment like this at the very bottom of the page:

Batcache will insert an HTML comment when it caches a page, as well as when it is serving a cached page.

Note that this article will only help resolve issues regarding page rendering. If you are looking to exempt database queries from your cache, you will need to manage those programmatically with object-cache.php functions in your theme or plugin code.

Specific Pages

Let’s imagine we want to exempt the following page from Batcache: https://testsite.com/nobatcache/

At the end of your wp-config.php file, you would want to add the lines of code below:

if ($_SERVER['REQUEST_URI'] == '/nobatcache/' && $batcache) {
  $batcache->max_age = 0;
}

This code will cancel Batcache from being used if the URI matches “/nobatcache/”. Note that if the page is already cached by your browser, you will need to clear your browser cache before the code modification above takes effect.

Specific IP Address

You also might want to exempt Batcache on a certain IP address: 123.456.789.10

At the end of your wp-config.php file, you could add the lines of code below:

if ($_SERVER['REMOTE_ADDR'] == '123.456.789.10' && $batcache) {
  $batcache->max_age = 0;
}

This code will cancel Batcache from being used if the URI matches “/nobatcache/”. Note that if the page is already cached by your browser, you will need to clear your browser cache before the code modification above takes effect.

Cookies

To exempt a user from seeing a cached version of any page on your site, you only need to set a cookie and ensure that the cookie name prefix begins with with ‘wp’ or ‘wordpress’, and Batcache will skip all subsequent pages loaded when the cookie is present.

Heads up!

If you notice your pages are not being served via Batcache, you might want to double check if some active plugins are generating any ‘wp’ or ‘wordpress’ prefixed cookies.

An Automattic Invention A family of WordPress solutions.