Prevent WP Rocket from Caching Filtered WooCommerce pages

When using WP Rocket with preloading in combination with a filter plugin like Filter Everything pro, then your database AND cache folder can explode. We had a site with only around 2000 Products, but with 100 filterable product attributes.

This resulted in wp_rocket_cache table over 2 million entries and the cache folder going up to 200GB. To fix this, we decided to stop wp rocket from caching filtered WooCommerce category pages.

The following code snippet solved our problem:

add_filter( 'rocket_preload_exclude_urls', function( $regexes, $url ) {
    
    $url = untrailingslashit( $url );

    if(function_exists('is_filtered')){
        if ( is_filtered() ) {
            $regexes[] = $url;
            add_filter( 'do_rocket_generate_caching_files', '__return_false' );
        }
    }

    if(function_exists('flrt_is_filter_request')){
        if ( flrt_is_filter_request() ) {
            $regexes[] = $url;
            add_filter( 'do_rocket_generate_caching_files', '__return_false' );
        }
    }

    return $regexes;
}, 10, 2 );

Leave a Reply

Your email address will not be published. Required fields are marked *

We use cookies to give you the best online experience. By agreeing you accept the use of cookies in accordance with our cookie policy.

Close Popup
Privacy Settings saved!
Privacy Settings

When you visit any web site, it may store or retrieve information on your browser, mostly in the form of cookies. Control your personal Cookie Services here.

These cookies are necessary for the website to function and cannot be switched off in our systems.

Technical Cookies
In order to use this website we use the following technically required cookies
  • wordpress_test_cookie
  • wordpress_logged_in_
  • wordpress_sec

Decline all Services
Save
Accept all Services