Ticket #22661: 22661-cache_via_filters-ext_object_filter.diff
File 22661-cache_via_filters-ext_object_filter.diff, 5.2 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 // Calling init on attached cache objects, if one or more loads; we have external cache 182 $result = apply_filters( 'wp_object_cache', false ); 183 if ( true === $result ) { 184 wp_using_ext_object_cache( true ); 185 } 186 187 // Create cache object in case of failing cache implementation or filters not being applied 141 188 $GLOBALS['wp_object_cache'] = new WP_Object_Cache(); 189 190 /* 191 * Because of the filter implementation this would not be called on 'first-run', 192 * and it would make sense to switch to the current blog on initialize 193 */ 194 global $blog_id; 195 wp_cache_switch_to_blog( $blog_id ); 196 142 197 } 143 198 144 199 /** … … 155 210 * @return bool False if not exists, true if contents were replaced 156 211 */ 157 212 function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) { 213 $result = apply_filters('wp_cache_replace', null, $key, $data, $group, (int) $expire); 214 if ( null !== $result ) { 215 return $result; 216 } 217 158 218 global $wp_object_cache; 159 219 160 220 return $wp_object_cache->replace( $key, $data, $group, (int) $expire ); … … 175 235 * @return bool False on failure, true on success 176 236 */ 177 237 function wp_cache_set( $key, $data, $group = '', $expire = 0 ) { 238 $result = apply_filters('wp_cache_set', null, $key, $data, $group, (int) $expire); 239 if ( null !== $result ) { 240 return $result; 241 } 242 178 243 global $wp_object_cache; 179 244 180 245 return $wp_object_cache->set( $key, $data, $group, (int) $expire ); … … 188 253 * @since 3.5.0 189 254 * 190 255 * @param int $blog_id Blog ID 256 * 257 * @return mixed|void 191 258 */ 192 259 function wp_cache_switch_to_blog( $blog_id ) { 260 $result = apply_filters( 'wp_cache_switch_to_blog', null, $blog_id ); 261 if ( null !== $result ) { 262 return $result; 263 } 264 193 265 global $wp_object_cache; 194 266 195 267 return $wp_object_cache->switch_to_blog( $blog_id ); … … 201 273 * @since 2.6.0 202 274 * 203 275 * @param string|array $groups A group or an array of groups to add 276 * 277 * @return mixed|void 204 278 */ 205 279 function wp_cache_add_global_groups( $groups ) { 280 $result = apply_filters('wp_cache_add_global_groups', null, $groups); 281 if ( null !== $result ) { 282 return $result; 283 } 206 284 global $wp_object_cache; 207 285 208 286 return $wp_object_cache->add_global_groups( $groups ); … … 214 292 * @since 2.6.0 215 293 * 216 294 * @param string|array $groups A group or an array of groups to add 295 * 296 * @return mixed|void 217 297 */ 218 298 function wp_cache_add_non_persistent_groups( $groups ) { 299 $result = apply_filters( 'wp_cache_add_non_persistent_groups', null, $groups ); 300 if ( null !== $result ) { 301 return $result; 302 } 219 303 // Default cache doesn't persist so nothing to do here. 220 304 return; 221 305 }