Skip to content

Commit

Permalink
$wpdb->get_results() will never return false here, so we don't need…
Browse files Browse the repository at this point in the history
… to rely upon the `$found` flag that's not available in all object caches.

This fixes job query caching when running on a persistent cache which doesn't implement the `$found` parameter or doesn't consider in-memory caches as "found" (see Automattic/wp-memcached#61).
  • Loading branch information
dd32 committed Jun 18, 2020
1 parent 99a6035 commit 151844f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions inc/class-job.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,9 @@ public static function get_jobs_by_query( $args = [] ) {
// Cache results.
$last_changed = wp_cache_get_last_changed( 'cavalcade-jobs' );
$query_hash = sha1( serialize( [ $sql, $sql_params ] ) ) . "::{$last_changed}";
$found = null;
$results = wp_cache_get( "jobs::{$query_hash}", 'cavalcade-jobs', true, $found );
$results = wp_cache_get( "jobs::{$query_hash}", 'cavalcade-jobs' );

if ( ! $found ) {
if ( false === $results ) {
$query = $wpdb->prepare( $sql, $sql_params );
$results = $wpdb->get_results( $query );
wp_cache_set( "jobs::{$query_hash}", $results, 'cavalcade-jobs' );
Expand Down

0 comments on commit 151844f

Please sign in to comment.