wp_start_object_cache

Start the WordPress object cache.

Description

wp_start_object_cache(); 

If an object-cache.php file exists in the wp-content directory, it uses that drop-in as an external object cache.


Usage

  1. if ( !function_exists( 'wp_start_object_cache' ) ) { 
  2. require_once ABSPATH . WPINC . '/load.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_start_object_cache(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/load.php  
  1. function wp_start_object_cache() { 
  2. global $wp_filter; 
  3.  
  4. $first_init = false; 
  5. if ( ! function_exists( 'wp_cache_init' ) ) { 
  6. if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { 
  7. require_once ( WP_CONTENT_DIR . '/object-cache.php' ); 
  8. if ( function_exists( 'wp_cache_init' ) ) { 
  9.  
  10. // Re-initialize any hooks added manually by object-cache.php 
  11. if ( $wp_filter ) { 
  12. $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter ); 
  13.  
  14. $first_init = true; 
  15. } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { 
  16. /** 
  17. * Sometimes advanced-cache.php can load object-cache.php before 
  18. * it is loaded here. This breaks the function_exists check above 
  19. * and can result in `$_wp_using_ext_object_cache` being set 
  20. * incorrectly. Double check if an external cache exists. 
  21. */ 
  22.  
  23. require_once ( ABSPATH . WPINC . '/cache.php' ); 
  24.  
  25. /** 
  26. * If cache supports reset, reset instead of init if already 
  27. * initialized. Reset signals to the cache that global IDs 
  28. * have changed and it may need to update keys and cleanup caches. 
  29. */ 
  30. if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) { 
  31. } elseif ( function_exists( 'wp_cache_init' ) ) { 
  32.  
  33. if ( function_exists( 'wp_cache_add_global_groups' ) ) { 
  34. wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) ); 
  35. wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );