diff --git a/admin/class-phpredis-purger.php b/admin/class-phpredis-purger.php index 1943b426..1492f569 100644 --- a/admin/class-phpredis-purger.php +++ b/admin/class-phpredis-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 `--mobile`, `--desktop`, `--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( '* * * * *' ); diff --git a/admin/class-predis-purger.php b/admin/class-predis-purger.php index 27a04cbd..efb5a7a0 100644 --- a/admin/class-predis-purger.php +++ b/admin/class-predis-purger.php @@ -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 `--mobile`, `--desktop`, `--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' ); + } + + } }