Can I extend the time Batcache caches my site?

By default, Batcache, our page caching mechanism, will cache pages for five minutes, if the pages get at least two visits in two minutes. This might be OK for a site that gets a lot of traffic, but could be an issue for a site that does not get a lot of traffic. How can your site take advantage of page caching if it is not highly trafficked and is mostly static?

The answer is to modify the variable settings of the Batcache class.

Let’s imagine that your Pressable site is static. You have a homepage about your company, as well as a few pages about your company and contact information. Furthermore, you want these pages to load from cache, despite your site not receiving a lot of traffic. In this case, you could insert the following code at the very end of your wp-config.php file:

// Custom Batcache settings for the end of wp-config.php
global $batcache;
if ($batcache && WP_CACHE) {
     $batcache->max_age = 86400;  // Seconds the cached render of a page will be stored
     $batcache->seconds = 3600;  // The amount of time at least 2 people are required to visit your page for a cached render to be stored.
}
// End custom Batcache settings

First, the above makes sure Batcache is being used and ensures that WP_CACHE is set to true.

Secondly, we change the $batcache class variables for max_age and seconds from 300 and 120 seconds to 86400 and 3600, respectively. In the case of max_age, this tells Batcache to hold onto a page for 24 hours, rather than the default 300 seconds. For seconds, it tells Batcache to cache the page if the page gets at least two page views in the period of one hour, rather than two minutes.

Finally, after adding the code modification above – feel free to adjust the times to your preferences – your site should load faster and more efficiently for more of your site’s visitors.

To learn more about Batcache, please see this article.

Try Pressable for 90 days, worry-free.

We promise you'll be imPressed with us or your money back.

Sign up now!