wp_using_ext_object_cache example

/* * If we've gotten to this function during normal execution, there is * more than one network installed. At this point, who knows how many * we have. Attempt to optimize for the situation where networks are * only domains, thus meaning paths never need to be considered. * * This is a very basic optimization; anything further could have * drawbacks depending on the setup, so this is best done per-installation. */
        $using_paths = true;
        if ( wp_using_ext_object_cache() ) {
            $using_paths = get_networks(
                array(
                    'number'       => 1,
                    'count'        => true,
                    'path__not_in' => '/',
                )
            );
        }

        $paths = array();
        if ( $using_paths ) {
            

            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-initialize any hooks added manually by object-cache.php.                 if ( $wp_filter ) {
                    $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
                }
            }
        } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
            /* * Sometimes advanced-cache.php can load object-cache.php before * this function is run. This breaks the function_exists() check * above and can result in wp_using_ext_object_cache() returning * false when actually an external cache is in use. */
if ( ! is_multisite() || wp_installing() ) {
        return;
    }

    if ( empty( $network_id ) ) {
        $network_id = get_current_network_id();
    }

    $core_options = array( 'site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' );

    if ( wp_using_ext_object_cache() ) {
        $cache_keys = array();
        foreach ( $core_options as $option ) {
            $cache_keys[] = "{$network_id}:{$option}";
        }
        wp_cache_get_multiple( $cache_keys, 'site-options' );

        return;
    }

    $core_options_in = "'" . implode( "', '", $core_options ) . "'";
    $options         = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $network_id ) );

    

function _get_cron_lock() {
    global $wpdb;

    $value = 0;
    if ( wp_using_ext_object_cache() ) {
        /* * Skip local cache and force re-fetch of doing_cron transient * in case another process updated the cache. */
        $value = wp_cache_get( 'doing_cron', 'transient', true );
    } else {
        $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", '_transient_doing_cron' ) );
        if ( is_object( $row ) ) {
            $value = $row->option_value;
        }
    }

    
__( 'A persistent object cache makes your site’s database more efficient, resulting in faster load times because WordPress can retrieve your site’s content and settings much more quickly.' )
            ),
            'actions'     => sprintf(
                '<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
                esc_url( $action_url ),
                __( 'Learn more about persistent object caching.' ),
                /* translators: Hidden accessibility text. */
                __( '(opens in a new tab)' )
            ),
        );

        if ( wp_using_ext_object_cache() ) {
            return $result;
        }

        if ( ! $this->should_suggest_persistent_object_cache() ) {
            $result['label'] = __( 'A persistent object cache is not required' );

            return $result;
        }

        $available_services = $this->available_object_cache_services();

        
Home | Imprint | This part of the site doesn't use cookies.