How to prevent Batcache page caching on Pressable

1 min , 15 sec read

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_cancel();
}

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 cookie, you only need to ensure that the cookie name prefix begins with with ‘wp’ or ‘wordpress’, and Batcache will not cache the value.

$cookie_name = "wp_user";

Heads up!

Using those prefixes will, by Batcache design, also stop the caching mechanism on all the pages that serve those cookies. Sometimes, 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.