How to change the behaviour of cache purge plugin?

Last Updated -


How to change the the behaviour pagely-cache-purge.php mu plugin?


By default, the Pagely Managment Plugin installed on all WP sites actively listens for WordPress hooks when a save_post/etc are triggered from the /wp-admin/ section, in which it does subsequent PURGE requests on the servers caching layer itself to clear the sites homepge/pages/feeds cached content. Which in practice would mean that visitors are always getting the latest news articles when they're updated.

But excessive cache purging on too many pages can degrade server performance. Disabling the cache purge can be done numerous ways. You can disable all or part of the cache PURGE requests that happen during a WP Post hook.

pagely_cache_purge_path hook can be used for changing cache purge behavior, used via add_filter. See examples below:

Disable All cache purge during WP Post save requests

Create custom plugin with a content below:

// disable cache purge (wp-content/mu-plugins/custom-stop-site-cache-purging.php)
add_filter('pagely_cache_purge_path', function($url) {

   // to disable purging "return null" from the filter - useful during batch imports, etc)
   return null; 

Disable purge for the homepage only, when only comments are made

Similar to previous example but for the homepage only:

// disable cache purge on comments from happening on homepage

add_filter('pagely_cache_purge_path', function($url) {
        if ($url == "/") {
            // Only stop homepage from purging
            return null;
        } else {
            return $url;

Disable during Cron run

// Add code to your cron at the top

Purge All Cache

if ( class_exists( 'PagelyCachePurge' ) ) {
        $purger = new PagelyCachePurge();

Purge Specific Items

if ( class_exists( 'PagelyCachePurge' ) ) {
    $purger = new PagelyCachePurge();

    // the pagely-cache-purge.php:purgePath() function is the main hook which checks & stops all subsequent PURGE requests.

Hooks for purging cache for everything/specific objects, used via apply_filters:

  • pagely_purge_all (yup, purge everything)
  • pagely_purge_comment
  • pagely_purge_post
  • pagely_purge_common (purge the front page, feeds, and contents of $PAGELY_CACHE_PURGE_ALWAYS)

You can set a variable called PAGELY_CACHE_PURGE_ALWAYS that specifies endpoints that you want to be purged any time a cache purge action takes place. This can be thrown into an MU plugin:


Related Topics

Pagely is the Managed WordPress Hosting Platform designed to exceed the needs of media, business, and Enterprise customers alike. We help the world's biggest brands scale WordPress.

Copyright © 2006-2017 Pagely, Inc. All rights reserved.
Pagely® and WordPress® are registered trademarks.

Powered by Zendesk