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

时间:2015-07-06 19:16:22

标签: php wordpress memcached

Zack Tollmanz为WordPress编写了一个新的Memcached对象缓存库。此库基于WordPress Memcache Plugin开发的Ryan Boren

WordPress带有default Object Cache。可以通过将名为object-cache.php文件的文件复制到wp-content文件夹的根目录来替换此默认缓存。 object-cache.php文件将包含替换对象缓存的实现。

Tollmanz Memcached对象缓存库不是插件。它是object-cache.php文件的替换版本。这是Tollmanz source code and installation instructions。问题是Tollmanz库假定PECL Memcached库安装在开发环境中并且存在Memcache Server实例。我们的项目中有多个开发人员,需要能够在未安装Memcached的本地开发环境(如笔记本电脑)中工作。当然,Memcache服务器和PECL库安装在我们的集成和生产环境中。

问题是如何设置Tollmanz Memcached对象缓存库,使其可以在没有安装Memcached的本地环境中使用?

1 个答案:

答案 0 :(得分:1)

好问题约翰。答案是创建一个" stub" object-cache.php文件并将其放入wp-content文件夹的根目录中。这个" stub'文件可以检查环境常量以确定是否加载Tollmanz Memcached对象缓存库。如果未加载Tollmanz Memcached Cache,则WordPress将恢复为其默认的对象缓存。

总结:

  1. 关注Tollmanz installations instructions
  2. 将Tollmanz object-cache.php文件复制到新的"插件"夹。这个 示例使用名为:/ plugins / pecl-memcached-object-cache /
  3. 的文件夹
  4. 复制以下" stub" object-cache.php文件放入/ wp-content文件夹。 WordPress将在引导序列的对象缓存设置部分加载此文件。
  5. 如果在wp-confile.php文件中定义了一个名为MEMCACHED_IS_ENABLED的常量,那么" stub"将加载Tollmanz对象缓存。否则它什么也不做,并使用默认的WordPress对象缓存。
  6. " stub"的源代码object-cache.php文件如下所列。
  7. 
        <?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);
        }