@@ -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