Zack Tollmanz为WordPress编写了一个新的Memcached对象缓存库。该库基于Ryan Boren开发的WordPress Memcache Plugin。
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服务器实例。我们的项目有多个开发人员,需要能够在没有安装Memcached的本地开发环境(如笔记本电脑)中工作。当然,Memcache服务器和PECL库安装在我们的集成和生产环境中。
问题是如何设置Tollmanz Memcached对象缓存库,使其可以在没有安装Memcached的本地环境中使用?
发布于 2015-07-07 03:16:22
问得好约翰。答案是创建一个"stub“object-cache.php文件,并将其放入wp-content文件夹的根目录中。这个“存根”文件可以检查环境常量,以确定是否加载Tollmanz Memcached对象缓存库。如果没有加载Tollmanz Memcached缓存,则WordPress将恢复为其默认的对象缓存。
总结一下:
插件跟随Tollmanz installations instructions
<?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);
}
https://stackoverflow.com/questions/31253851
复制相似问题