宝塔面板安装Memcached
进入左侧的软件商店,找到 Memcached 1.5.16安装,然后在PHP相对应的版本中安装拓展,如下图所示:
下载object-cache.php和advanced-cache.php
将以下两个文件上传到/wp-content/目录,注意不是/wp-content/plugins/目录。
下载地址:object-cache.php和advanced-cache.php
上述所说步骤做完之后,编辑博客根目录的wp-config.php 文件,添加下方两段代码进去并保存:
//激活Batcache
define('ENABLE_CACHE', true);
//激活Memcached
define('WP_CACHE', true);
上方步骤完成之后,进入后台已安装插件,如下图所示,就已经开启了Memcached 缓存功能,试试打开速度,是不是飞快?
advanced-cache.php有一些自定义的选项可供配置,我们打开源代码编辑调成成下面的模式。
var $max_age = 3600; // Expire batcache items aged this many seconds (zero to disable batcache)
var $remote = 0; // Zero disables sending buffers to remote datacenters (req/sec is never sent)
var $times = 2; // Only batcache a page after it is accessed this many times… (two or more)
var $seconds = 0; // …in this many seconds (zero to ignore this and use batcache immediately)
max_age代表缓存过期时间(以秒为单位),times表示访问多少次才创建缓存(2是最小值),seconds表示在多少秒之后才创建缓存(0表示立即)