简体   繁体   English

如何在本地开发环境中使用WordPress安装Tollmanz Memcached对象缓存

[英]How to install the Tollmanz Memcached Object Cache with WordPress in Local Dev Environments

Zack Tollmanz has written a new Memcached Object Cache Library for WordPress. Zack Tollmanz为WordPress编写了一个新的Memcached对象缓存库。 This library is based on the WordPress Memcache Plugin developed by Ryan Boren . 该库基于Ryan Boren开发的WordPress Memcache插件

WordPress comes with a default Object Cache . WordPress带有默认的对象缓存 This default Cache can be replaced by copying a file called object-cache.php file into the root of the wp-content folder. 可以通过将名为object-cache.php的文件复制到wp-content文件夹的根目录中来替换此默认Cache。 The object-cache.php file would contain an implementation of the replacement Object Cache. object-cache.php文件将包含替换对象缓存的实现。

The Tollmanz Memcached Object Cache Library is not a Plugin. Tollmanz Memcached对象缓存库不是插件。 It is a replacement version of the object-cache.php file. 它是object-cache.php文件的替代版本。 Here is the Tollmanz source code and installation instructions . 这是Tollmanz 源代码和安装说明 The problem is that the Tollmanz Library assumes that the PECL Memcached library is installed in the Development Environment and that a Memcache Server instance exists. 问题是Tollmanz库假定PECL Memcached库已安装在开发环境中,并且存在Memcache Server实例。 We have multiple developers on our project and need to be able to work in local Development Environments (like laptops) where Memcached is not installed. 我们的项目有多个开发人员,因此需要能够在未安装Memcached的本地开发环境(例如笔记本电脑)中工作。 The Memcache Servers and PECL libraries of course are installed in our Integration and Production Environments. 当然,Memcache服务器和PECL库已安装在我们的集成和生产环境中。

The question is how to setup the Tollmanz Memcached Object Cache Library in a way that it can be used in local environments that do not have Memcached installed? 问题是如何设置Tollmanz Memcached对象缓存库,使其可以在未安装Memcached的本地环境中使用?

Good question John. 约翰,好问题。 The answer is to create a "stub" object-cache.php file and place it into the root of the wp-content folder. 答案是创建一个“存根” object-cache.php文件,并将其放置在wp-content文件夹的根目录中。 This "stub' file can check an Environment Constant to determine whether to load the Tollmanz Memcached Object Cache Library. If the Tollmanz Memcached Cache is not loaded then WordPress will revert to its default Object Cache. 该“存根”文件可以检查环境常数,以确定是否加载Tollmanz Memcached对象缓存库。如果未加载Tollmanz Memcached缓存,则WordPress将还原为其默认的对象缓存。

To summarize: 总结一下:

  1. Follow the Tollmanz installations instructions 遵循Tollmanz安装说明
  2. Copy the Tollmanz object-cache.php file into a new "plugins" folder. 将Tollmanz object-cache.php文件复制到新的“ plugins”文件夹中。 This example used a folder called: /plugins/pecl-memcached-object-cache/ 这个例子使用了一个文件夹:/ plugins / pecl-memcached-object-cache /
  3. Copy the below "stub" object-cache.php file into the /wp-content folder. 将下面的“存根” object-cache.php文件复制到/ wp-content文件夹中。 WordPress will load this file during the object cache setup part of the bootstrap sequence. WordPress将在引导程序序列的对象缓存设置过程中加载此文件。
  4. If a Constant called MEMCACHED_IS_ENABLED is defined in the wp-confile.php file then the "stub" will load the Tollmanz Object Cache. 如果在wp-confile.php文件中定义了一个称为MEMCACHED_IS_ENABLED的常量,则“存根”将加载Tollmanz对象缓存。 Otherwise it does nothing and the default WordPress Object Cache is used. 否则,它什么都不做,并使用默认的WordPress对象缓存。
  5. The source code for the "stub" object-cache.php file is listed below. 下面列出了“存根” object-cache.php文件的源代码。

    <?php
    //
    // WordPress PECL Memcached Object Cache Stub File
    //
    // Name this file "object-cache.php" and place in the root of the /wp-content folder.  
    //
    // This "stub" file integrates WordPress with the Tollmanz PECL Memcached Object Cache
    // https://github.com/tollmanz/wordpress-pecl-memcached-object-cache
    //
    // This Constant can be defined in the wp-config.php file.
    if (defined('MEMCACHED_IS_ENABLED') && MEMCACHED_IS_ENABLED) {  

        // The Tollmanz Memcached Object Cache uses this global variable for the list of Memcached Servers
        global $memcached_servers;
        $memcached_servers = array(
            array(
                '127.0.0.1', // Memcached server IP address
                11211        // Memcached server port
            )
        );

        // Load the Tollmanz Memcached Library  
        // This example assumes that the Library file was copied to a plugins folder called "pecl-memcached-object-cache".
        $memcache_plugin_file = dirname(__FILE__) . '/plugins/pecl-memcached-object-cache/object-cache.php';
        require_once($memcache_plugin_file);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM