Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #203 from rtCamp/feature/add-wildcard-keys-deletion
Browse files Browse the repository at this point in the history
Add wildcard cache key deletion for device type cache purge
  • Loading branch information
pradeep910 committed Jul 1, 2019
2 parents 4c24e5c + 352cbe2 commit a871cd4
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 5 deletions.
40 changes: 36 additions & 4 deletions admin/class-phpredis-purger.php
Expand Up @@ -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( '* * * * *' );
Expand Down
40 changes: 39 additions & 1 deletion admin/class-predis-purger.php
Expand Up @@ -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' );
}

}

}

Expand Down

0 comments on commit a871cd4

Please sign in to comment.