Ticket #19564: 19564.patch

File 19564.patch, 1.3 KB (added by johnjamesjacoby, 18 months ago)
  • wp-includes/cache.php

     
    216216} 
    217217 
    218218/** 
     219 * Attempt to retrieve a value from the cache. If it is not already set, the 
     220 * callback function is attempted. If that does not return a result, the 
     221 * $default is used. The $result is then set in the cache, and returned. 
     222 * 
     223 * This is a helper, and does not have a partner method in WP_Object_Cache 
     224 *  
     225 * @since 3.4 
     226 * @param int|string $key What to call the contents in the cache 
     227 * @param mixed $default The default contents to cache 
     228 * @param string Optional $callback Function name to call if cache not set 
     229 * @param string Optional $group Where to group the cache contents 
     230 * @param int Optional $expire When to expire the cache contents 
     231 * @return mixed The cache contents on cache hit, the callback or default on cache miss 
     232 */ 
     233function wp_cache_attempt( $key, $default, $callback = '', $group = '', $expire = 0 ) { 
     234        $result = wp_cache_get( $key, $group ); 
     235        if ( ! $result ) { 
     236                if ( $callback ) { 
     237                        $result = call_user_func( $callback ); 
     238                } 
     239                if ( ! $result ) { 
     240                        $result = $default; 
     241                } 
     242                wp_cache_set( $key, $result, $group, $expire ); 
     243        } 
     244        return $result; 
     245} 
     246 
     247/** 
    219248 * WordPress Object Cache 
    220249 * 
    221250 * The WordPress Object Cache is used to save on trips to the database. The