This page contains advanced customization options for BigScoots Cache and is intended for developers. If you don't know how to write code, please do not try to tinker with these options as it can lead to breaking your website.
BigScoots Cache not only has an extensive settings page to manage every part of page caching, but also has many actions, filters, and helper methods to allow you to customize your page caching experience.
Configuring the plugin with PHP Constants
The BigScoots Cache plugin has support for the following PHP constants that you can add inside wp-config.php to overwrite the default values:
BS_CACHE_CURL_TIMEOUT— timeout in seconds for cURL calls (default: 10)BS_CACHE_HOME_PAGE_SHOWS_POSTS— if the front page a.k.a. the home page of the website, shows the latest posts (default:true[bool])
Modifying the plugin behaviors with Filters
Filters let you fine-tune the plugin's behavior by adding small code snippets (e.g. in your theme's functions.php or a code snippets plugin). Here are the filters provided by this plugin.
Cache Specific URLs That Would Otherwise Be Bypassed
Filter name: bs_cache_cacheable_url_patterns — [3 Arguments - $patterns (Array), $request_uri (String), $rest_route (String)]
If a URL or URL pattern is bypassed from cache and you would like to cache that URL pattern (or a sub-pattern of it), use this filter to list the URL patterns (WP REST API or normal path) that should be cached even if a default rule asks the plugin to bypass them. * works as a wildcard.
$rest_route is only filled in when the WP REST API bypass option is turned on, and the request is a REST API call made with ?rest_route=.
add_filter('bs_cache_cacheable_url_patterns', function(array $patterns, string $request_uri, string $rest_route) : array {
$patterns[] = '/wp-json/foo-app/v1*'; // a WP REST API endpoint
$patterns[] = '/promo/*'; // a normal path in your bypass list
return $patterns;
}, 10, 3);Make Bypassed URLs Cacheable for Logged-in Users
Filter name: bs_cache_logged_in_user_cacheable_url_patterns — [1 Argument - $patterns (Array)]
Only for the Boost plan with cache for logged-in users turned on. URLs that match these patterns are cached per user instead of being bypassed. They are never shared between users.
add_filter('bs_cache_logged_in_user_cacheable_url_patterns', function(array $patterns) : array {
$patterns[] = '/my-account/some-page*';
$patterns[] = '/account/test*';
return $patterns;
});Bypass Cache
Filter name: bs_cache_cache_bypass — [1 Argument - $bypass (Bool)]
Return true to bypass BigScoots Cache for the current request. Always add a condition; otherwise, the cache is bypassed for the whole website.
add_filter('bs_cache_cache_bypass', function(bool $bypass) : bool {
if (is_page('live-scores')) {
return true; // bypass cache for this page only
}
return $bypass;
});Bypass cache on every page while a WooCommerce notice is pending
Filter name: bs_cache_bypass_woo_notices_sitewide — [1 Argument - $bypass (Bool)]
When a visitor has a pending WooCommerce notice (e.g. "Product added to cart"), BigScoots Cache bypasses the cache on WooCommerce pages (shop, product, cart, checkout, account) so the notice is not cached for everyone. If your theme shows WooCommerce notices on every page, use this filter to bypass the cache site-wide while a notice is pending.
add_filter('bs_cache_bypass_woo_notices_sitewide', '__return_true');Post Types to ignore from cache purge operation
Filter name: bs_cache_ignored_post_types — [1 Argument - $list_of_post_types (Array)]
Many WordPress websites have custom post types that never need a cache purge (e.g. shop_order, shop_coupon, attachment). By default, BigScoots Cache purges cache for changes in every post type except the ones excluded in the plugin settings. Use this filter to add more post types to that list.
add_filter('bs_cache_ignored_post_types', function(array $list_of_post_types) : array {
$list_of_post_types[] = 'shop_order';
$list_of_post_types[] = 'shop_coupon';
$list_of_post_types[] = 'attachment';
$list_of_post_types[] = 'some_other_cpt';
return $list_of_post_types;
});Add more web pages to the related URL list
Filter name: bs_cache_post_related_url_init — [2 Arguments - $list_of_urls (Array), $post_id (Int)]
When you publish or update a post, BigScoots Cache purges the cache for that post and its related pages (home page, category, tag and other taxonomy pages, author and archive pages, along with their paginated pages).
If there is a page that should also be purged whenever you publish or update content, use this filter to add it to the related URL list.
add_filter('bs_cache_post_related_url_init', function(array $list_of_urls) : array {
$list_of_urls[] = home_url('/some-page/');
$list_of_urls[] = home_url('/some-other-page/');
return $list_of_urls;
});The same filter, using the post ID to add a page only for a specific post type:
add_filter('bs_cache_post_related_url_init', function(array $list_of_urls, int $post_id) : array {
if (get_post_type($post_id) === 'job_listing') {
$list_of_urls[] = home_url('/job-board/');
}
return $list_of_urls;
}, 10, 2);Tip: For a single page, you can also turn on Purge this page when other content changes in the BigScoots Cache box on the page's edit screen. That page is then purged whenever any post or page on the site is published, updated, or deleted. This works well for pages that list other content, such as a Query Loop page.
Disable Related URLs purge
Filter name: bs_cache_disable_related_urls_purge — [2 Arguments - $disable_related_urls_purge (Bool), $post_id (Int)]
Please Note: Using this filter is highly discouraged unless you have a specific reason for it. When it is enabled, the plugin won't purge the cache for any related URLs like the home page, taxonomy, author, or other archive pages. Only the post that was published or updated gets purged.
// Disable related URLs purge for the entire site
add_filter('bs_cache_disable_related_urls_purge', '__return_true');
// Disable related URLs purge for certain post IDs only
add_filter('bs_cache_disable_related_urls_purge', function(bool $disable_related_urls_purge, int $post_id) : bool {
if ($post_id === 10 || $post_id === 20) {
$disable_related_urls_purge = true;
}
return $disable_related_urls_purge;
}, 10, 2);
Purge the entire page cache on every post update
Filter name: bs_cache_auto_purge_entire_page_cache — [1 Argument - $purge_entire_page_cache (Bool)]
Return true to purge the entire page cache (HTML only, not static files) whenever a post is published, updated, or deleted, instead of purging only that post and its related pages. Use it only if your site shows content in places the related-page purge can't reach.
add_filter('bs_cache_auto_purge_entire_page_cache', '__return_true');Post types that purge the entire page cache
Filter name: bs_cache_full_purge_post_types — [1 Argument - $post_types (Array)]
Some post types don't have a page of their own but change every page on the site. For these, BigScoots Cache purges the entire page cache when they are edited. By default these are the block theme types wp_template, wp_template_part, wp_navigation and wp_global_styles. Use this filter to add your own.
add_filter('bs_cache_full_purge_post_types', function(array $post_types) : array {
$post_types[] = 'my_site_wide_banner';
return $post_types;
});Choose which post types show the BigScoots Cache box
Filter name: bs_cache_meta_box_post_types — [1 Argument - $post_types (Array)]
The BigScoots Cache box on the post edit screen lets you bypass the cache for a single post or page. It is shown on every public post type, except the post types excluded in the plugin settings. Use this filter to add or remove post types by their name (e.g. product).
add_filter('bs_cache_meta_box_post_types', function(array $post_types) : array {
// Hide the box on WooCommerce products
return array_values(array_diff($post_types, ['product']));
});Offer "Purge this page when other content changes" on more post types
Filter name: bs_cache_related_page_post_types — [1 Argument - $post_types (Array)]
By default, the Purge this page when other content changes option is only shown on Pages. If a page builder or theme uses its own post type for pages, add it here.
add_filter('bs_cache_related_page_post_types', function(array $post_types) : array {
$post_types[] = 'my_landing_page';
return $post_types;
});Set the CDN Cache TTL dynamically
Filter name: bs_cache_cdn_cache_ttl — [1 Argument - $cdn_cache_ttl (Int)]
Changes the max-age value inside the CDN-Cache-Control header, which tells BigScoots Cache how long a page is cached at the CDN level.
For logged-in user cache (Boost), single event pages from The Events Calendar and Polylang per-language domains, the CDN TTL is capped at 10 hours, and this filter can't raise it above that.
add_filter('bs_cache_cdn_cache_ttl', function(int $cdn_cache_ttl) : int {
if (is_page('latest')) { // the page with the slug 'latest'
$cdn_cache_ttl = 2 * WEEK_IN_SECONDS;
} elseif (is_page('test-page')) { // the page with the slug 'test-page'
$cdn_cache_ttl = 5 * MONTH_IN_SECONDS;
}
return $cdn_cache_ttl;
});Set the Browser Cache TTL dynamically
Filter name: bs_cache_browser_cache_ttl — [1 Argument - $browser_cache_ttl (Int)]
Changes the max-age value inside the Cache-Control header, which tells the browser how long to cache a page.
add_filter('bs_cache_browser_cache_ttl', function(int $browser_cache_ttl) : int {
if (is_page('latest')) {
$browser_cache_ttl = 0; // don't let the browser cache this page
} elseif (is_page('test-page')) {
$browser_cache_ttl = 10; // cache it in the browser for 10 seconds only
}
return $browser_cache_ttl;
});Set the CDN Cache Stale-While-Revalidate TTL dynamically
Filter name: bs_cache_stale_while_revalidate — [1 Argument - $swr_ttl (Int), default 60]
Changes the stale-while-revalidate value inside the CDN-Cache-Control header: how long an expired page can still be served from the CDN while a fresh copy is fetched.
add_filter('bs_cache_stale_while_revalidate', function(int $swr_ttl) : int {
if (is_page('latest')) {
$swr_ttl = 10; // 10 seconds
}
return $swr_ttl;
});Set the CDN Cache Stale-If-Error TTL dynamically
Filter name: bs_cache_stale_if_error — [1 Argument - $sie_ttl (Int), default 3600]
Changes the stale-if-error value inside the CDN-Cache-Control header: how long an expired page can still be served from the CDN while the origin server returns a 5XX or other error.
add_filter('bs_cache_stale_if_error', function(int $sie_ttl) : int {
if (is_page('latest')) {
$sie_ttl = 10; // 10 seconds
}
return $sie_ttl;
});Modify the Cache-Control value dynamically
Filter name: bs_cache_control — [1 Argument - $cache_control (String)]
add_filter('bs_cache_control', function(string $cache_control) : string {
if (is_singular('example')) {
$cache_control = 'no-cache, no-store, max-age=0, must-revalidate';
}
return $cache_control;
});Modify the CDN-Cache-Control value dynamically
Filter name: bs_cache_control_cdn — [1 Argument - $cdn_cache_control (String)]
add_filter('bs_cache_control_cdn', function(string $cdn_cache_control) : string {
if (is_singular('example')) {
$cdn_cache_control = 'no-cache, no-store, max-age=0, must-revalidate';
}
return $cdn_cache_control;
});Add your own cache tags to a page
Filter name: bs_cache_response_cache_tags — [2 Arguments - $extra_cache_tags (Array), $cache_tags (Array)]
Adds extra cache tags to the page being served. $cache_tags holds the tags BigScoots Cache already added. Use only letters, numbers, _ and - in a tag.
add_filter('bs_cache_response_cache_tags', function(array $extra_cache_tags, array $cache_tags) : array {
if (is_page('pricing')) {
$extra_cache_tags[] = 'pricing_table';
}
return $extra_cache_tags;
}, 10, 2);Query params ignored for cache tags
Filter name: bs_cache_ignored_query_params_for_cache_tags — [1 Argument - $params (Array)]
By default, pagination params and the ignored marketing query params don't change a page's cache tags. So /page/?utm_source=x is purged together with /page/. Add a param here if it should also be treated the same way.
add_filter('bs_cache_ignored_query_params_for_cache_tags', function(array $params) : array {
$params[] = 'my_tracking_id';
return $params;
});XML / Feed cache filters
Feeds and other dynamic XML pages (like sitemaps) get their own, shorter cache values. Each of these filters takes 1 argument and works like its page-cache version above.
Filter name | What it changes | Default |
| CDN cache TTL ( | 300 seconds |
| Browser cache TTL ( | 0 seconds |
|
| 60 seconds |
|
| 21600 seconds |
| The full | - |
| The full | - |
// CDN cache TTL: cache feeds for 10 minutes at the CDN
add_filter('bs_cache_xml_cdn_cache_ttl', function(int $cdn_ttl) : int {
return 10 * MINUTE_IN_SECONDS;
});
// Browser cache TTL: let the browser cache feeds for 1 minute
add_filter('bs_cache_xml_browser_cache_ttl', function(int $browser_cache_ttl) : int {
return MINUTE_IN_SECONDS;
});
// Stale-while-revalidate: serve an expired feed for up to 2 minutes while a fresh copy is fetched
add_filter('bs_cache_xml_stale_while_revalidate', function(int $swr_ttl) : int {
return 2 * MINUTE_IN_SECONDS;
});
// Stale-if-error: serve an expired feed for up to 1 day while the server returns an error
add_filter('bs_cache_xml_stale_if_error', function(int $sie_ttl) : int {
return DAY_IN_SECONDS;
});
// Full Cache-Control value: never let the browser cache feeds
add_filter('bs_cache_xml_cache_control', function(string $cache_control) : string {
return 'no-cache, no-store, max-age=0, must-revalidate';
});
// Full CDN-Cache-Control value: set every CDN value yourself
add_filter('bs_cache_xml_cdn_cache_control', function(string $cdn_cache_control) : string {
return 'max-age=600, stale-while-revalidate=120, stale-if-error=86400';
});
The two full-value filters run last and replace the values built from the four TTL filters above them. Use one or the other, not both.
Include custom URL patterns to be treated as Feed
Filter name: bs_cache_dynamic_xml_url_patterns — [1 Argument - $url_patterns (Array)]
If a plugin generates custom feed URLs that WordPress doesn't recognize as feeds, add their URL patterns here so BigScoots Cache treats them as feeds.
add_filter('bs_cache_dynamic_xml_url_patterns', function(array $url_patterns) : array {
$url_patterns[] = '/some-feed/*';
$url_patterns[] = '/foo/bar/*';
return $url_patterns;
});To decide in code instead of by URL, return true from bs_cache_is_dynamic_xml_request [1 Argument - $is_dynamic_xml (Bool)]
add_filter('bs_cache_is_dynamic_xml_request', function(bool $is_dynamic_xml) : bool {
return isset($_GET['my_feed']) ? true : $is_dynamic_xml;
});Preload static files leveraging Early Hints
Filter name: bs_cache_early_hint_preloads — [1 Argument - $preloads (Array)]
BigScoots Cache has a native integration with the Perfmatters plugin: every item added as "Preload" or "Critical Image" in Perfmatters is preloaded using Early Hints.
If you don't use Perfmatters, use this filter to pass the critical static assets you want preloaded with Early Hints. Each item needs a url and an as value (image, font, script or style).
add_filter('bs_cache_early_hint_preloads', function(array $preloads) : array {
if (is_page('contact')) {
$preloads[] = [
'url' => 'https://example.com/wp-content/uploads/2021/01/contact.js',
'as' => 'script'
];
} elseif (is_page('portfolio')) {
$preloads[] = [
'url' => 'https://example.com/wp-content/uploads/2021/01/portfolio.css',
'as' => 'style'
];
}
return $preloads;
});Leave responsive images out of Early Hints
Filter name: bs_cache_early_hints_skip_responsive_images — [1 Argument - $skip (Bool)]
By default, every image added as "Preload" or "Critical Image" in Perfmatters, or passed through bs_cache_early_hint_preloads, is sent as an Early Hint. That is the fastest way to start loading your main image, but an Early Hint can only point to one image file. It can't use the image's srcset to pick a size for the visitor's screen.
So if your main image has several sizes, a visitor whose screen needs a different size downloads the image twice. For example, a phone downloads the full-size image from the Early Hint and then the smaller size the page asks for.
Return true to leave images that have srcset, sizes or media out of Early Hints. Perfmatters still preloads them in the page's HTML, so the browser picks the right size and downloads it once. Fonts, scripts, styles and images without srcset are still sent as Early Hints.
// Leave responsive images out of Early Hints everywhere
add_filter('bs_cache_early_hints_skip_responsive_images', '__return_true');
// Only on the homepage
add_filter('bs_cache_early_hints_skip_responsive_images', function(bool $skip) : bool {
return is_front_page() ? true : $skip;
});
Add or remove response headers
Use these two filters to add your own response headers, or remove headers set by WordPress or another plugin. Common uses: adding a Link header to the homepage, adding a Content-Signal header for AI crawlers, or replacing a header value another plugin sends.
Both filters run on every front-end page, and on feeds and sitemaps. They do not run on redirects, REST API requests, the WordPress admin, the login page, or AJAX requests.
Filter name: bs_cache_add_response_headers — [3 Arguments - $headers (Array), $mode (String), $context (Array)]
Adds headers to the response. Return an array of header name => value. To send the same header more than once, use an array of values.
add_filter('bs_cache_add_response_headers', function(array $headers, string $mode, array $context) : array {
// Every response
$headers['Content-Signal'] = 'search=yes, ai-input=yes, ai-train=no';
// Homepage only
if (is_front_page()) {
$headers['Link'] = '</wp-json/>; rel="service-desc"';
}
// The same header with two values
$headers['Vary'] = ['Accept', 'Cookie'];
return $headers;
}, 10, 3);Filter name: bs_cache_remove_response_headers — [3 Arguments - $header_names (Array), $mode (String), $context (Array)]
Removes headers from the response. Return an array of header names.
add_filter('bs_cache_remove_response_headers', function(array $header_names, string $mode, array $context) : array {
$header_names[] = 'X-Test-Header';
return $header_names;
}, 10, 3);Replacing a header's value
Added headers never replace an existing header with the same name; they are sent alongside it. To change a value, remove the header and then add it again. Removals always run before additions.
// Replace the X-Frame-Options value set by another plugin
add_filter('bs_cache_remove_response_headers', function(array $header_names) : array {
$header_names[] = 'X-Frame-Options';
return $header_names;
});
add_filter('bs_cache_add_response_headers', function(array $headers) : array {
$headers['X-Frame-Options'] = 'SAMEORIGIN';
return $headers;
});
The $mode argument
Value | Meaning |
| The response will be cached. |
| The response bypasses the cache (for example a logged-in visitor, a POST request or an excluded URL). |
| BigScoots Cache is turned off. |
A header added to a cached response is cached with the page and served to every visitor. Never add a value that depends on the visitor, such as a user ID. To add a header only to responses that are not cached, check $mode:
add_filter('bs_cache_add_response_headers', function(array $headers, string $mode) : array {
if ($mode !== 'cache') {
$headers['X-Debug-Rendered'] = 'origin';
}
return $headers;
}, 10, 2);The $context argument
Key | Type | Description |
| String | The requested path with its query string, for example |
| Object or null | The post, term, or user being shown, the same as |
| Int | The ID of the queried object. This is a post ID on a post or page, a term ID on a category or tag archive, and |
| Int | The HTTP status code, for example |
| Bool |
|
Example: add a header to one post, and to sitemaps but not regular pages.
add_filter('bs_cache_add_response_headers', function(array $headers, string $mode, array $context) : array {
if ($context['queried_object_id'] === 42) {
$headers['X-Robots-Tag'] = 'noarchive';
}
if ($context['is_dynamic_xml']) {
$headers['X-Content-Source'] = 'sitemap';
}
return $headers;
}, 10, 3);Feeds and sitemaps
Some sitemap generators finish the response before WordPress loads the page. To reach them, the filters run once early, and again later if the request gets that far. Return the same values both times: a different value on the second run is added next to the first, not instead of it.
On the early run, the main query hasn't run yet.
queried_objectisnull,queried_object_idis0,status_codeis200, and conditional tags such asis_front_page()oris_feed()returnfalse. Use$context['is_dynamic_xml']or$context['request_uri']to target feeds and sitemaps.A removal only reaches headers already set when the filter runs. Headers an SEO plugin sets while building its sitemap, such as Rank Math's
X-Robots-Tag: noindex, can't be removed this way.
What these filters can't change
Headers BigScoots Cache manages. These names are ignored in both filters:
- everyX-BigScoots-*header;
-Cache-Control,CDN-Cache-Control,Cloudflare-CDN-Cache-Control,Pragma,ExpiresandCache-Tag;
-Set-Cookie,Content-Type,Content-Length,Content-Encoding,Transfer-Encoding,Connection,LocationandStatus.Linkheaders can be added but not removed. WordPress and BigScoots Cache send their ownLinkheaders, so yours are added alongside them.Headers added by the web server, such as
Vary: Accept-Encoding, or anX-Frame-Optionsset in the nginx configuration. These are added after WordPress finishes, so these filters can't remove or replace them. If you add a header with the same name (likeVary: Accept), the response carries both lines. To change a server-level header, contact BigScoots support.Invalid entries are skipped: a header name with anything other than letters, numbers, and hyphens, or a value that is empty or contains a line break.
Turn off Speculation Rules on specific pages
Filter name: bs_cache_speculation_rules_enabled — [1 Argument - $enabled (Bool)]
add_filter('bs_cache_speculation_rules_enabled', function(bool $enabled) : bool {
return is_page('checkout-landing') ? false : $enabled;
});Add URL patterns to the Speculation Rules exclude list
Filter name: bs_cache_speculation_href_exclude_paths — [1 Argument - $href_exclude_paths (Array)]
add_filter('bs_cache_speculation_href_exclude_paths', function(array $href_exclude_paths) : array {
$href_exclude_paths[] = '/account*'; // e.g. /account, /accounts, /account/some-page/
$href_exclude_paths[] = '/test-post/'; // e.g. /test-post/, /test-post/?foo=bar
$href_exclude_paths[] = '/*\\?*(^|&)(foo|loo|poo)=*'; // any URL with a foo=, loo= or poo= query param
return $href_exclude_paths;
});Change Speculation Mode from Prerender (default) to Prefetch
Filter name: bs_cache_speculation_mode — [1 Argument - $mode (String)]
Only prerender and prefetch are accepted. Any other value falls back to prerender.
add_filter('bs_cache_speculation_mode', fn() => 'prefetch');Modify the Speculation Rules before they are added
Filter name: bs_cache_speculation_rules — [1 Argument - $rules (Array)]
add_filter('bs_cache_speculation_rules', function(array $rules) : array {
// Modify the speculation rules as you see fit
return $rules;
});Disable OPCache purge that happens via BigScoots Cache
Filter name: bs_cache_disable_clear_opcache
add_filter('bs_cache_disable_clear_opcache', '__return_true');Disable Object Cache purge that happens via BigScoots Cache
Filter name: bs_cache_disable_clear_object_cache
add_filter('bs_cache_disable_clear_object_cache', '__return_true');Stop purging WooCommerce products when only the stock quantity changes
Filter name: bs_cache_woo_purge_on_stock_quantity_change — [2 Arguments - $purge (Bool), $product_id (Int)]
By default, a product's cache is purged when its stock quantity changes (e.g. after an order). Return false to skip that purge. A product going in or out of stock is always purged.
// Skip for all products
add_filter('bs_cache_woo_purge_on_stock_quantity_change', '__return_false');
// Skip for certain products only
add_filter('bs_cache_woo_purge_on_stock_quantity_change', function(bool $purge, int $product_id) : bool {
return in_array($product_id, [123, 456], true) ? false : $purge;
}, 10, 2);
Polylang: let Polylang set its language cookie with a header
Filter name: bs_cache_polylang_cache_active — [1 Argument - $cache_active (Bool)]
BigScoots Cache tells Polylang that pages are cached, so Polylang sets its language cookie with JavaScript. A cookie header would stop the page from being cached. Return false only if you need Polylang's default behavior back.
add_filter('bs_cache_polylang_cache_active', '__return_false');The Events Calendar: custom Calendar Embeds URL
Filter name: bs_cache_tec_calendar_embed_url_prefix — [1 Argument - $url_prefix (String), default home_url('/calendar-embed/')]
When an event is added, updated or deleted, BigScoots Cache purges The Events Calendar's embedded calendars under /calendar-embed/. If your site serves them from another path, set it here.
add_filter('bs_cache_tec_calendar_embed_url_prefix', fn() => home_url('/embedded-calendar/'));Advanced tuning filters
Change these only if BigScoots Support asks you to. The defaults suit almost every site.
Filter name | What it controls | Default |
| Max posts purged in one batch; bigger queues are split into several batches | 2000 |
| Max purge requests sent to the CDN at the same time | 10 |
| Seconds after any purge during which an asset-cache flush from another plugin (e.g. Autoptimize, Asset CleanUp) doesn't trigger another full page purge | 60 |
| Seconds before the same product is purged again for a stock quantity change | 60 |
| Seconds during which a product save that changed nothing is not purged again | 600 |
| Max grouped-product child/parent links tracked for purging | 10000 |
| Seconds before an Easy Digital Downloads product is purged again for the same sales stats | 600 |
| Easy Digital Downloads settings that purge the page cache when changed (currency, button text, taxes, etc.) | built-in list |
| WordPress actions where Divi's "clear everything" signal is skipped because BigScoots Cache already purges what changed | built-in list |
// Purge at most 500 posts per batch
add_filter('bs_cache_purge_queue_max', function(int $max_posts_per_batch) : int {
return 500;
});
// Send at most 5 purge requests to the CDN at the same time
add_filter('bs_cache_cf_api_max_concurrency', function(int $max_concurrency) : int {
return 5;
});
// Skip asset-cache flushes from other plugins for 2 minutes after a purge
add_filter('bs_cache_asset_flush_echo_window', function(int $seconds) : int {
return 2 * MINUTE_IN_SECONDS;
});
// Purge a product again for a stock quantity change only after 5 minutes
add_filter('bs_cache_woo_product_purge_throttle', function(int $seconds) : int {
return 5 * MINUTE_IN_SECONDS;
});
// Skip purging a product save that changed nothing for 30 minutes
add_filter('bs_cache_woo_product_update_purge_throttle', function(int $seconds) : int {
return 30 * MINUTE_IN_SECONDS;
});
// Track up to 20,000 grouped-product child/parent links
add_filter('bs_cache_woo_grouped_map_max_entries', function(int $max_entries) : int {
return 20000;
});
// Purge an EDD product again for the same sales stats only after 30 minutes
add_filter('bs_cache_edd_download_stats_purge_throttle', function(int $seconds) : int {
return 30 * MINUTE_IN_SECONDS;
});
// Also purge the page cache when an EDD add-on setting changes
add_filter('bs_cache_edd_visible_settings', function(array $settings) : array {
$settings[] = 'my_addon_price_label';
return $settings;
});
// Skip Divi's "clear everything" signal on one more action
add_filter('bs_cache_divi_covered_actions', function(array $actions) : array {
$actions[] = 'my_plugin_after_import';
return $actions;
});
Modifying the plugin behaviors with Actions
Actions run before or after a certain operation. Here are the actions provided by this plugin.
Fired after the whole cache is purged (purge everything)
Action name: bs_cache_purge_all
Fires after everything for the website (pages and static files) has been purged.
add_action('bs_cache_purge_all', function() : void {
// BigScoots Cache has purged everything. Run your custom code here.
});Fired after the entire page cache is purged (HTML only)
Action name: bs_cache_purge_all_page_cache — [1 Argument: $html_cache_tag (String)]
Fires after every HTML page has been purged. Static files are not touched.
add_action('bs_cache_purge_all_page_cache', function(string $html_cache_tag) : void {
// All pages were purged. Run your custom code here.
});Fired after caches for specific URLs are purged
Action name: bs_cache_purge_urls — [3 Arguments: $urls (Array), $exact_urls (Array), $cache_tags (Array)]
$urls are purged as prefixes (the URL and everything under it), `$exact_urls` are purged as exact matches (query string included), and `$cache_tags` are the cache tags purged.
add_action('bs_cache_purge_urls', function(array $urls, array $exact_urls, array $cache_tags) : void {
// The cache for these URLs and tags has been purged. Run your custom code here.
}, 10, 3);Fired after the cache for specific users is purged
Action name: bs_cache_purge_users — [1 Argument: $user_ids (Array)]
Boost plan with cache for logged-in users only.
add_action('bs_cache_purge_users', function(array $user_ids) : void {
// The cache for these users has been purged. Run your custom code here.
});Fired after the Object Cache is flushed
Action name: bs_cache_object_cache_flushed
add_action('bs_cache_object_cache_flushed', function() : void {
// The object cache was flushed. Run your custom code here.
});Fired before and after the whole cache is purged (purge everything)
Action names: bs_cache_purge_whole_cache_before and bs_cache_purge_whole_cache_after
Fires right before and right after the request that purges everything for the website (pages and static files).
add_action('bs_cache_purge_whole_cache_before', function() : void {
// About to purge everything.
});
add_action('bs_cache_purge_whole_cache_after', function() : void {
// Everything has been purged.
});Fired before and after the cache for specific URLs is purged
Action names: bs_cache_purge_cache_by_urls_before and bs_cache_purge_cache_by_urls_after — [3 Arguments: $urls (Array), $exact_urls (Array), $cache_tags (Array)]
Fires right before and right after the request that purges a list of URLs and cache tags.
add_action('bs_cache_purge_cache_by_urls_before', function(array $urls, array $exact_urls, array $cache_tags) : void {
// About to purge these URLs and tags.
}, 10, 3);
add_action('bs_cache_purge_cache_by_urls_after', function(array $urls, array $exact_urls, array $cache_tags) : void {
// These URLs and tags have been purged.
}, 10, 3);Fired before and after the cache for specific users is purged
Action names: bs_cache_purge_cache_by_users_before and bs_cache_purge_cache_by_users_after — [1 Argument: $user_ids (Array)]
Boost plan with cache for logged-in users only.
add_action('bs_cache_purge_cache_by_users_before', function(array $user_ids) : void {
// About to purge the cache for these users.
});
add_action('bs_cache_purge_cache_by_users_after', function(array $user_ids) : void {
// The cache for these users has been purged.
});Purging the OPCache programmatically
The server OPCache can be purged programmatically with the following code:
if (class_exists('BigScoots_Cache') && method_exists('BigScoots_Cache', 'clear_opcache')) {
\BigScoots_Cache::clear_opcache();
}Purging the Object Cache programmatically
The Object Cache can be purged programmatically with the following code:
if (class_exists('BigScoots_Cache') && method_exists('BigScoots_Cache', 'clear_object_cache')) {
\BigScoots_Cache::clear_object_cache();
}Purging the cache programmatically
You can purge BigScoots Cache from your theme's functions.php, and third-party plugins can use the same code to purge BigScoots Cache when they need to. It supports:
Purge everything for the entire domain (pages and static files)
Purge the entire page cache (HTML only)
Purge cache for a specific Post ID, with or without its related pages (home page, taxonomy, category, author and other archive pages)
Purge cache for a list of Post IDs (an integer array), with or without their related pages
Purge cache for a list of URLs
Purge cache for a list of exact URLs, including their query string
Purge cache for a list of User IDs (an integer array) — Boost plan with cache for logged-in users only
Every call returns an array like ['success' => true, 'message' => 'Purged entire domain cache.'], so you can check the result if you need to.
if (class_exists('BigScoots_Cache') && method_exists('BigScoots_Cache', 'clear_cache')) {
// Use only the line you need. Each one below is a separate purge.
// Purge everything for the entire domain (pages and static files)
\BigScoots_Cache::clear_cache('purge_everything');
// Purge the entire page cache (HTML only)
\BigScoots_Cache::clear_cache('purge_page_cache');
// Purge a specific Post ID, but not its related pages
\BigScoots_Cache::clear_cache(85);
// Purge a specific Post ID and its related pages
\BigScoots_Cache::clear_cache(85, true);
// Purge a list of Post IDs, but not their related pages
\BigScoots_Cache::clear_cache([85, 96, 102]);
// Purge a list of Post IDs and their related pages
\BigScoots_Cache::clear_cache([85, 96, 102], true);
// Purge a list of URLs (each URL and everything under it)
\BigScoots_Cache::clear_cache(['https://example.com/test/', 'https://example.com/category/uncategorized/']);
// Purge the exact URL only, query string included, instead of everything under it
\BigScoots_Cache::clear_cache(['https://example.com/foo/?license=abc1234'], false, false, true);
// Purge the page cache for specific users (by user ID)
\BigScoots_Cache::clear_cache([1045, 2541, 3002, 1526], false, true);
}