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.

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' has values, do not cache.
	if ( ! empty( $atts['facet_args']['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.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