Skip to content

Commit c4dc90d

Browse files
committed
Purge single site Redis cache in multisite setup
See PR: #122
1 parent 02dab11 commit c4dc90d

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

‎redis-purger.php‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -672,12 +672,22 @@ function purge_on_check_ajax_referer( $action, $result )
672672
function true_purge_all()
673673
{
674674
global $rt_wp_nginx_helper;
675-
$prefix = substr($rt_wp_nginx_helper->options['redis_prefix'],0, -1);
676-
$this->log( "* * * * *" );
677-
$this->log( "* Purged Everything!" );
678-
$this->log( "* * * * *" );
679-
//delete_multi_keys("*");
680-
delete_keys_by_wildcard($prefix."*");
675+
$prefix = trim( $rt_wp_nginx_helper->options['redis_prefix'] );
676+
677+
$this->log( '* * * * *' );
678+
679+
// If Purge Cache link click from network admin then purge all
680+
if( is_network_admin() ) {
681+
delete_keys_by_wildcard( $prefix . '*' );
682+
$this->log( '* Purged Everything! * ' );
683+
} else { // Else purge only site specific cache
684+
$parse = wp_parse_url( get_site_url() );
685+
$parse['path'] = empty( $parse['path'] ) ? '/' : $parse['path'];
686+
delete_keys_by_wildcard( $prefix . $parse['scheme'] . 'GET' . $parse['host'] . $parse['path'] . '*' );
687+
$this->log( '* ' . get_site_url() . ' Purged! * ' );
688+
}
689+
690+
$this->log( '* * * * *' );
681691
}
682692

683693
function purge_urls()
@@ -717,7 +727,7 @@ function purge_urls()
717727
}
718728
}
719729
}
720-
}
730+
}
721731
}
722732

723733
}

0 commit comments

Comments
 (0)