Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wildcard cache key deletion for device type cache purge #203

Merged
merged 2 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions admin/class-phpredis-purger.php
Original file line number Diff line number Diff line change
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 );
chandrapatel marked this conversation as resolved.
Show resolved Hide resolved
} 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' );
chandrapatel marked this conversation as resolved.
Show resolved Hide resolved
} 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
Original file line number Diff line number Diff line change
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