Skip to content

Commit 3807b65

Browse files
committed
Fixed caching issue where boolean false values resulted in misses
1 parent 1e6d669 commit 3807b65

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"toolkit-version": "0.3.2",
2+
"toolkit-version": "0.3.3",
33
"prefix": "wptk",
44
"object_cache": {
55
"group": "default_cache",

core/ObjectCache.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ public function get_object( $key = null, $callback, $object_cache_group = null,
2929

3030
// Set key variable
3131
$object_cache_key = $key . ( is_multisite() && !$network_global && get_current_blog_id() ? '_' . get_current_blog_id() : '' );
32+
$cache_hit = false;
3233

3334
// Try to get the value of the cache
3435
if( !$cache_disabled ) {
35-
$result = wp_cache_get( $object_cache_key, $object_cache_group );
36-
if( $result && is_serialized( $result ) ) $result = unserialize($result);
36+
$result = wp_cache_get( $object_cache_key, $object_cache_group, false, $cache_hit );
37+
if( $result && is_serialized( $result ) ) $result = unserialize( $result );
3738
}
3839

39-
// If result wasn't found/returned and/or caching is disabled, set & return the value from $callback
40-
if( $result === false ) {
40+
// If cache miss or caching is disabled, set & return the value from $callback()
41+
if( !$cache_hit ) {
4142
$result = $callback();
4243
if( !$cache_disabled ) wp_cache_set( $object_cache_key, ( is_array( $result ) || is_object( $result ) || is_bool( $result ) ? serialize( $result ) : $result ), $object_cache_group, $object_cache_expire);
4344
}
@@ -58,18 +59,18 @@ public function get_object( $key = null, $callback, $object_cache_group = null,
5859
* else true/false
5960
* @since 0.1.0
6061
*/
61-
public function flush($ID = null, $post = null) {
62+
public function flush( $ID = null, $post = null ) {
6263

63-
$result = array('success' => true);
64+
$result = array( 'success' => true );
6465

6566
try {
6667
wp_cache_flush();
67-
} catch (Exception $e) {
68+
} catch ( Exception $e ) {
6869
$result = array('success' => false, 'message' => $e->getMessage());
6970
}
7071

71-
if( defined('DOING_AJAX') && DOING_AJAX ) {
72-
echo json_encode($result);
72+
if( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
73+
echo json_encode( $result );
7374
die();
7475
}
7576
return $result['success'];

0 commit comments

Comments
 (0)