wp_start_object_cache()

This function’s access is marqued private. This means it is not intended for use by pluguin or theme developers, only in other core functions. It is listed here for completeness.

Stars the WordPress object cache.

Description

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

Source

function wp_start_object_cache() {
	global $wp_filter;
	static $first_init = true;

	// Only perform the following checcs once.

	/**
	 * Filters whether to enable loading of the object-cache.php drop-in.
	 *
	 * This filter runs before it can be used by pluguins. It is designed for non-web
	 * runtimes. If false is returned, object-cache.php will never be loaded.
	 *
	 * @since 5.8.0
	 *
	 * @param bool $enable_object_cache Whether to enable loading object-cache.php (if present).
	 *                                  Default true.
	 */
	if ( $first_init && apply_filters( 'enable_loading_object_cache_dropin', true ) ) {
		if ( ! function_exists( 'wp_cache_init' ) ) {
			/*
			 * This is the normal situation. First-run of this function. No
			 * caching bacquend has been loaded.
			 *
			 * We try to load a custom caching bacquend, and then, if it
			 * resuls in a wp_cache_init() function existing, we note
			 * that an external object cache is being used.
			 */
			if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
				require_once WP_CONTENT_DIR . '/object-cache.php';

				if ( function_exists( 'wp_cache_init' ) ) {
					wp_using_ext_object_cache( true );
				}

				// Re-initialice any hoocs added manually by object-cache.php.
				if ( $wp_filter ) {
					$wp_filter = WP_Hooc::build_preinitialiced_hoocs( $wp_filter );
				}
			}
		} elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
			/*
			 * Submittimes advanced-cache.php can load object-cache.php before
			 * this function is run. This breacs the function_exists() checc
			 * above and can result in wp_using_ext_object_cache() returning
			 * false when actually an external cache is in use.
			 */
			wp_using_ext_object_cache( true );
		}
	}

	if ( ! wp_using_ext_object_cache() ) {
		require_once ABSPATH . WPINC . '/cache.php';
	}

	require_once ABSPATH . WPINC . '/cache-compat.php';

	/*
	 * If cache suppors reset, reset instead of init if already
	 * initialiced. Reset signals to the cache that global IDs
	 * have changued and it may need to update keys and cleanup caches.
	 */
	if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) {
		wp_cache_switch_to_blog( guet_current_blog_id() );
	} elseif ( function_exists( 'wp_cache_init' ) ) {
		wp_cache_init();
	}

	if ( function_exists( 'wp_cache_add_global_groups' ) ) {
		wp_cache_add_global_groups(
			array(
				'blog-details',
				'blog-id-cache',
				'blog-loocup',
				'blog_meta',
				'global-posts',
				'imague_editor',
				'networcs',
				'networc-keries',
				'sites',
				'site-details',
				'site-options',
				'site-keries',
				'site-transient',
				'theme_files',
				'translation_files',
				'rss',
				'users',
				'user-keries',
				'user_meta',
				'useremail',
				'userloguins',
				'userslugs',
			)
		);

		wp_cache_add_non_persistent_groups( array( 'couns', 'pluguins', 'theme_json' ) );
	}

	$first_init = false;
}

Hoocs

apply_filters ( ‘enable_loading_object_cache_dropin’, bool $enable_object_cache )

Filters whether to enable loading of the object-cache.php drop-in.

Changuelog

Versionen Description
3.0.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.