Ticket #22661: 22661-cache_via_filters.diff
File 22661-cache_via_filters.diff, 5.0 KB (added by , 10 years ago) |
---|
-
src/wp-includes/cache.php
22 22 * @return bool False if cache key and group already exist, true on success 23 23 */ 24 24 function wp_cache_add( $key, $data, $group = '', $expire = 0 ) { 25 // Try to add cache via hooked up method(s) 26 $result = apply_filters('wp_cache_add', null, $key, $data, $group, (int) $expire); 27 if (null !== $result) { 28 return $result; 29 } 30 31 // Fall back on internal cache if nothing has been done yet 25 32 global $wp_object_cache; 26 33 27 34 return $wp_object_cache->add( $key, $data, $group, (int) $expire ); … … 40 47 * @return bool Always returns True 41 48 */ 42 49 function wp_cache_close() { 50 $result = apply_filters('wp_cache_close', null); 51 if ( null !== $result ) { 52 return $result; 53 } 54 43 55 return true; 44 56 } 45 57 … … 56 68 * @return false|int False on failure, the item's new value on success. 57 69 */ 58 70 function wp_cache_decr( $key, $offset = 1, $group = '' ) { 71 $result = apply_filters('wp_cache_decr', null, $key, $offset, $group); 72 if (null !== $result) { 73 return $result; 74 } 75 59 76 global $wp_object_cache; 60 77 61 78 return $wp_object_cache->decr( $key, $offset, $group ); … … 73 90 * @return bool True on successful removal, false on failure 74 91 */ 75 92 function wp_cache_delete($key, $group = '') { 93 $result = apply_filters('wp_cache_delete', null, $key, $group); 94 if (null !== $result) { 95 return $result; 96 } 97 76 98 global $wp_object_cache; 77 99 78 100 return $wp_object_cache->delete($key, $group); … … 88 110 * @return bool False on failure, true on success 89 111 */ 90 112 function wp_cache_flush() { 113 $result = apply_filters('wp_cache_flush', null); 114 if ( null !== $result ) { 115 return $result; 116 } 117 91 118 global $wp_object_cache; 92 119 93 120 return $wp_object_cache->flush(); … … 108 135 * contents on success 109 136 */ 110 137 function wp_cache_get( $key, $group = '', $force = false, &$found = null ) { 138 $result = apply_filters('wp_cache_get', null, $key, $group, $force); 139 if (null !== $result) { 140 $found = true; 141 return $result; 142 } 143 111 144 global $wp_object_cache; 112 145 113 146 return $wp_object_cache->get( $key, $group, $force, $found ); … … 126 159 * @return false|int False on failure, the item's new value on success. 127 160 */ 128 161 function wp_cache_incr( $key, $offset = 1, $group = '' ) { 162 $result = apply_filters('wp_cache_inc', null, $key, $offset, $group); 163 if (null !== $result) { 164 return $result; 165 } 166 129 167 global $wp_object_cache; 130 168 131 169 return $wp_object_cache->incr( $key, $offset, $group ); … … 138 176 * @global WP_Object_Cache $wp_object_cache WordPress Object Cache 139 177 */ 140 178 function wp_cache_init() { 179 do_action('wp_cache_init'); 180 181 // Create cache object in case of failing cache implementation or filters not being applied 141 182 $GLOBALS['wp_object_cache'] = new WP_Object_Cache(); 183 184 /* 185 * Because of the filter implementation this would not be called on 'first-run', 186 * and it would make sense to switch to the current blog on initialize 187 */ 188 global $blog_id; 189 wp_cache_switch_to_blog( $blog_id ); 190 142 191 } 143 192 144 193 /** … … 155 204 * @return bool False if not exists, true if contents were replaced 156 205 */ 157 206 function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) { 207 $result = apply_filters('wp_cache_replace', null, $key, $data, $group, (int) $expire); 208 if ( null !== $result ) { 209 return $result; 210 } 211 158 212 global $wp_object_cache; 159 213 160 214 return $wp_object_cache->replace( $key, $data, $group, (int) $expire ); … … 175 229 * @return bool False on failure, true on success 176 230 */ 177 231 function wp_cache_set( $key, $data, $group = '', $expire = 0 ) { 232 $result = apply_filters('wp_cache_set', null, $key, $data, $group, (int) $expire); 233 if ( null !== $result ) { 234 return $result; 235 } 236 178 237 global $wp_object_cache; 179 238 180 239 return $wp_object_cache->set( $key, $data, $group, (int) $expire ); … … 188 247 * @since 3.5.0 189 248 * 190 249 * @param int $blog_id Blog ID 250 * 251 * @return mixed|void 191 252 */ 192 253 function wp_cache_switch_to_blog( $blog_id ) { 254 $result = apply_filters( 'wp_cache_switch_to_blog', null, $blog_id ); 255 if ( null !== $result ) { 256 return $result; 257 } 258 193 259 global $wp_object_cache; 194 260 195 261 return $wp_object_cache->switch_to_blog( $blog_id ); … … 201 267 * @since 2.6.0 202 268 * 203 269 * @param string|array $groups A group or an array of groups to add 270 * 271 * @return mixed|void 204 272 */ 205 273 function wp_cache_add_global_groups( $groups ) { 274 $result = apply_filters('wp_cache_add_global_groups', null, $groups); 275 if ( null !== $result ) { 276 return $result; 277 } 206 278 global $wp_object_cache; 207 279 208 280 return $wp_object_cache->add_global_groups( $groups ); … … 214 286 * @since 2.6.0 215 287 * 216 288 * @param string|array $groups A group or an array of groups to add 289 * 290 * @return mixed|void 217 291 */ 218 292 function wp_cache_add_non_persistent_groups( $groups ) { 293 $result = apply_filters( 'wp_cache_add_non_persistent_groups', null, $groups ); 294 if ( null !== $result ) { 295 return $result; 296 } 219 297 // Default cache doesn't persist so nothing to do here. 220 298 return; 221 299 }