Skip to content

Commit da2054d

Browse files
authored
Merge pull request #2654 from WordPress/feature/directdatabasequery-update-function-lists
DB/DirectDatabaseQuery: allow for more caching functions
2 parents 7629477 + 13e2eda commit da2054d

File tree

3 files changed

+60
-15
lines changed

3 files changed

+60
-15
lines changed

WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ final class DirectDatabaseQuerySniff extends Sniff {
8282
* @var array
8383
*/
8484
protected $cacheGetFunctions = array(
85-
'wp_cache_get' => true,
85+
'wp_cache_get' => true,
86+
'wp_cache_get_multiple' => true,
87+
'wp_cache_get_multiple_salted' => true,
88+
'wp_cache_get_salted' => true,
8689
);
8790

8891
/**
@@ -95,8 +98,12 @@ final class DirectDatabaseQuerySniff extends Sniff {
9598
* @var array
9699
*/
97100
protected $cacheSetFunctions = array(
98-
'wp_cache_set' => true,
99-
'wp_cache_add' => true,
101+
'wp_cache_add' => true,
102+
'wp_cache_add_multiple' => true,
103+
'wp_cache_set' => true,
104+
'wp_cache_set_multiple' => true,
105+
'wp_cache_set_multiple_salted' => true,
106+
'wp_cache_set_salted' => true,
100107
);
101108

102109
/**
@@ -109,18 +116,21 @@ final class DirectDatabaseQuerySniff extends Sniff {
109116
* @var array
110117
*/
111118
protected $cacheDeleteFunctions = array(
112-
'wp_cache_delete' => true,
113-
'clean_attachment_cache' => true,
114-
'clean_blog_cache' => true,
115-
'clean_bookmark_cache' => true,
116-
'clean_category_cache' => true,
117-
'clean_comment_cache' => true,
118-
'clean_network_cache' => true,
119-
'clean_object_term_cache' => true,
120-
'clean_page_cache' => true,
121-
'clean_post_cache' => true,
122-
'clean_term_cache' => true,
123-
'clean_user_cache' => true,
119+
'wp_cache_delete' => true,
120+
'wp_cache_delete_multiple' => true,
121+
'wp_cache_flush_group' => true,
122+
'wp_cache_flush_runtime' => true,
123+
'clean_attachment_cache' => true,
124+
'clean_blog_cache' => true,
125+
'clean_bookmark_cache' => true,
126+
'clean_category_cache' => true,
127+
'clean_comment_cache' => true,
128+
'clean_network_cache' => true,
129+
'clean_object_term_cache' => true,
130+
'clean_page_cache' => true,
131+
'clean_post_cache' => true,
132+
'clean_term_cache' => true,
133+
'clean_user_cache' => true,
124134
);
125135

126136
/**

WordPress/Tests/DB/DirectDatabaseQueryUnitTest.1.inc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,34 @@ function callToMultiLevelNamespaceRelativeCacheDelete() {
475475
$wpdb->query( 'SELECT X FROM Y' ); // Warning direct DB call.
476476
namespace\Sub\clean_blog_cache( 1 );
477477
}
478+
479+
// Handle more caching functions.
480+
function cache_multiple() {
481+
global $wpdb;
482+
$data = wp_cache_get_multiple( ['keyA', 'keyB'] );
483+
if ( false !== $data ) {
484+
$data = $wpdb->get_results( $query ); // Warning direct DB call.
485+
\wp_cache_add_multiple( $data );
486+
}
487+
}
488+
489+
function cache_multiple_salted() {
490+
global $wpdb;
491+
$data = \wp_cache_get_multiple_salted( ...$params );
492+
if ( false !== $data ) {
493+
$data = $wpdb->get_col( $query ); // Warning direct DB call.
494+
wp_cache_set_multiple_salted( ...$params );
495+
}
496+
}
497+
498+
function cache_delete_multiple() {
499+
global $wpdb;
500+
$wpdb->replace( $query ); // Warning direct DB call.
501+
WP_cache_delete_multiple( ['keyA', 'keyB'] );
502+
}
503+
504+
function cache_flush_group() {
505+
global $wpdb;
506+
$wpdb->delete( $query ); // Warning direct DB call.
507+
wp_cache_flush_group( 'group' );
508+
}

WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public function getWarningList( $testFile = '' ) {
109109
461 => 1,
110110
468 => 1,
111111
475 => 1,
112+
484 => 1,
113+
493 => 1,
114+
500 => 1,
115+
506 => 1,
112116
);
113117
default:
114118
return array();

0 commit comments

Comments
 (0)