Cache invalidation with multiple domains on one WordPress installation
-
Hi Breeze team,
First of all, thanks for the great plugin! I’ve recently switched from WP Super Cache to Breeze and I’m very happy with it so far.
I noticed a small issue when using two domains for the same WordPress installation (
example.atas the primary domain andexample.deas an additional domain).Breeze correctly creates and serves separate caches for both domains. However, when updating a page or product, only the cache for the primary domain is invalidated. The cached version on the second domain remains unchanged.
Looking at the code, it seems that
collect_urls_for_cache_purge()collects URLs based on the primary WordPress domain.I found a simple workaround using the existing
breeze_collect_urls_for_cache_purgefilter to add the corresponding URLs for the second domain.I understand that supporting multiple domains on a single WordPress installation may be an uncommon setup, but maybe my feedback helps.
Thanks again for your work!
My current workaround:
add_filter( 'breeze_collect_urls_for_cache_purge', function ( $urls ) {
$domains = [
'www.example.at',
'www.example.de',
];
foreach ( $urls as $url ) {
$host = wp_parse_url( $url, PHP_URL_HOST );
if ( in_array( $host, $domains, true ) ) {
foreach ( $domains as $domain ) {
$urls[] = str_replace( $host, $domain, $url );
}
}
}
return array_unique( $urls );
} );
You must be logged in to reply to this topic.