Skip to content
Permalink
Browse files

Merge pull request #203 from rtCamp/feature/add-wildcard-keys-deletion

Add wildcard cache key deletion for device type cache purge
  • Loading branch information...
pradeep910 committed Jul 1, 2019
2 parents 4c24e5c + 352cbe2 commit a871cd4459c5e63c02530b78233187a4cb50873f
Showing with 75 additions and 5 deletions.
  1. +36 −4 admin/class-phpredis-purger.php
  2. +39 −1 admin/class-predis-purger.php
@@ -120,12 +120,44 @@ public function purge_url( $url, $feed = true ) {
$prefix = $nginx_helper_admin->options['redis_prefix'];
$_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'] . $parse['path'];
$is_purged = $this->delete_single_key( $_url_purge_base );
if ( $is_purged ) {
$this->log( '- Purged URL | ' . $url );
/**
* To delete device type caches such as `<URL>--mobile`, `<URL>--desktop`, `<URL>--lowend`, etc.
* This would need $url above to be changed with this filter `rt_nginx_helper_purge_url` by cache key that Nginx sets while generating cache.
*
* For example: If page is accessed from desktop, then cache will be generated by appending `--desktop` to current URL.
* Add this filter in separate plugin or simply in theme's function.php file:
* ```
* add_filter( 'rt_nginx_helper_purge_url', function( $url ) {
* $url = $url . '--*';
* return $url;
* });
* ```
*
* Regardless of what key / suffix is being to store `$device_type` cache , it will be deleted.
*
* @since 2.1.0
*/
if ( strpos( $_url_purge_base, '*' ) === false ) {
$status = $this->delete_single_key( $_url_purge_base );
if ( $status ) {
$this->log( '- Purge URL | ' . $_url_purge_base );
} else {
$this->log( '- Cache Not Found | ' . $_url_purge_base, 'ERROR' );
}
} else {
$this->log( '- Cache Not Found | ' . $url, 'ERROR' );
$status = $this->delete_keys_by_wildcard( $_url_purge_base );
if ( $status ) {
$this->log( '- Purge Wild Card URL | ' . $_url_purge_base . ' | ' . $status . ' url purged' );
} else {
$this->log( '- Cache Not Found | ' . $_url_purge_base, 'ERROR' );
}
}
$this->log( '* * * * *' );
@@ -119,7 +119,45 @@ public function purge_url( $url, $feed = true ) {
$prefix = $nginx_helper_admin->options['redis_prefix'];
$_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'] . $parse['path'];
$this->delete_single_key( $_url_purge_base );
/**
* To delete device type caches such as `<URL>--mobile`, `<URL>--desktop`, `<URL>--lowend`, etc.
* This would need $url above to be changed with this filter `rt_nginx_helper_purge_url` by cache key that Nginx sets while generating cache.
*
* For example: If page is accessed from desktop, then cache will be generated by appending `--desktop` to current URL.
* Add this filter in separate plugin or simply in theme's function.php file:
* ```
* add_filter( 'rt_nginx_helper_purge_url', function( $url ) {
* $url = $url . '--*';
* return $url;
* });
* ```
*
* Regardless of what key / suffix is being to store `$device_type` cache , it will be deleted.
*
* @since 2.1.0
*/
if ( strpos( $_url_purge_base, '*' ) === false ) {
$status = $this->delete_single_key( $_url_purge_base );
if ( $status ) {
$this->log( '- Purge URL | ' . $_url_purge_base );
} else {
$this->log( '- Cache Not Found | ' . $_url_purge_base, 'ERROR' );
}
} else {
$status = $this->delete_keys_by_wildcard( $_url_purge_base );
if ( $status ) {
$this->log( '- Purge Wild Card URL | ' . $_url_purge_base . ' | ' . $status . ' url purged' );
} else {
$this->log( '- Cache Not Found | ' . $_url_purge_base, 'ERROR' );
}
}
}

0 comments on commit a871cd4

Please sign in to comment.
You can’t perform that action at this time.