Caching

←  All Add-Ons

Speed up loading time when filtering grids or templates by caching content and facets. Caching add-on boost performances by storing queried content in a custom table.

The cache should not be used if you render content conditionally or by random order. Otherwise, a single version will be cached and rendered regardless of conditions.

Key features

  • Cache content for all asynchronous requests
  • Clear cache individually on each page
  • Clear cache globally for all pages
  • Exclude facets or grids from cache
  • Control the cache lifespan
  • WP-CLI command to clear cache

Usage

Once the add-on activated, a new “Caching” menu will appear in the global settings of WP Grid Builder. And a menu in the admin bar, to clear the cache, will be available.

By default, the plugin will cache all requests from all your grids and facets. But, you can exclude grids and facets in the global settings.

We recommand to exclude Search facets from cache to prevent caching an infinite number of results. Because, filtering combinations are endless with a search facet.

Screenshots

Cache - Global settings
Cache – Global settings
Cache - Admin menu
Cache – Admin menu
Cache - HTTP header
Cache – HTTP header

Documentation

This add-on comes with several PHP filters to easily customize the cache behaviour.

Bypass the cache:

PHP
functions.php
function prefix_bypass_cache( $bypass, $atts ) {

	// If facet slug '_search' (prefixed) has values, do not cache.
	if ( ! empty( $_GET['_search'] ) ) {
		return true;
	}

	return $bypass;

}
add_filter( 'wp_grid_builder_caching/bypass', 'prefix_bypass_cache', 10, 2 );

Change the cache lifespan:

PHP
functions.php
function prefix_cache_lifespan( $interval ) {

	// Lifespan in seconds.
	return 24 * HOUR_IN_SECONDS;

}
add_filter( 'wp_grid_builder_caching/lifespan', 'prefix_cache_lifespan', 10, 2 );

Change the cron interval used to cleanup expired cache content:

PHP
functions.php
function prefix_cron_interval( $interval ) {

	// Interval in seconds.
	return 30 * MINUTE_IN_SECONDS;

}
add_filter( 'wp_grid_builder_caching/cron_interval', 'prefix_cron_interval', 10, 2 );

Disable cron jobs, ran each 24 hours, that clear expired cache content:

PHP
functions.php
add_filter( 'wp_grid_builder_caching/cron', '__return_false' );

Easily clear or cleanup cache with WP-CLI:

WP-CLI
Terminal
# Clear whole cache.
$ wp wpgb-caching clear
Success: Cache cleared!

# Clear grid cache from grid id.
$ wp wpgb-caching clear 1234
Success: Cache cleared for 1234!

# Clear grid cache from template id.
$ wp wpgb-caching clear "My Template"
Success: Cache cleared for My Template!

# Cleanup cache (expired content).
$ wp wpgb-caching cleanup
Success: Cache cleaned up!

Changelog

v1.2.0

Release date: April 2, 2024

  • addedSupport for WP Grid Builder V2.

v1.1.0

Release date: February 6, 2023

  • addedCompatibility with PHP 8.2.

v1.0.7

Release date: January 13, 2020

  • improvedBetter detection of facets in page to clear current page cache.

v1.0.6

Release date: December 15, 2020

  • fixedCaching conflict when Multilingual add-on is activated.

v1.0.5

Release date: November 23, 2020

  • changedCaching query string parameters principle.

v1.0.4

Release date: October 19, 2020

  • fixedIssue with grids and templates detection on page.

v1.0.3

Release date: April 14, 2019

  • addedFrench translation of backend and frontend.

v1.0.2

Release date: March 25, 2019

  • addedNew automatic purge option.
  • addedSupport for WP Grid Builder v1.2.1
  • fixedWarning when creating custom table on activation.

v1.0.1

Release date: November 5, 2019

  • fixedIssue with custom table creation.

v1.0.0

Release date: November 4, 2019

  • released Public Release