效果
同样不多比比,直接看效果(已经关闭了 WP Super Cache):




刷新网页时,后台 CPU 占用仍然是满的:

前后网页加载时间并没有太大变化,说明我的 WordPress 加载性能瓶颈不在查数据库上,而就是因为 CPU 性能不足导致动态生成网页过慢,不加钱升级配置就只能用静态网页了。
刚开始用的数据:

虽然性能提升很小,但是万一以后我有了大豪斯服务器,又有很多访客(想屁吃),这时候说不定查数据库就变成瓶颈了呢。
memcached 原理
作为内存对象缓存的一种(另一种就是 Javaer 都熟知的 Redis),memcached 减少数据库查询次数的原理很简单,就是把查表的结果缓存起来,下次就不用再查一次,直接从内存中调用上一次的结果就行了。除了查内存,其实还能缓存很多东西(这个“对象”可是包罗万象的),比如 WP Super Cache 的对头 W3 Total Cache 就支持用 memcached 缓存更多乱七八糟的东西(WP Super Cache 似乎以前可以在实验性功能启用 memcached,但是我现在找不到设置)。
安装 memcached
宝塔面板安装特别简单,在 WordPress 所使用的 php 上启用扩展就行了。如果你不是宝塔,请自行百度其他教程。

在 WordPress 中启用 memcached
原教程:https://baijiahao.baidu.com/s?id=1739522036697829121
单单是安装还不够,还得告诉 WordPress 怎么利用 memcached,这就需要一个 object-cache.php 文件了。此外,还可选一个后台管理页面看看缓存的命中率。
object-cache.php 很多地方都有的下,但是鱼龙混杂,这里就选用 WPJAM BASIC 这个插件(https://cn.wordpress.org/plugins/wpjam-basic/),比较省心省力(这个插件还有很多有用的功能,就是扩展功能要关注他的公众号有点恶心)
安装完并启用后,在宝塔的文件管理中打开 WPJAM BASIC 下面的 template 文件夹,把 object-cache.php 复制到 WP根目录/wp-content 下面:


然后就没了, WP 会自动识别并启用。可以在 WPJAM 的系统信息查看缓存命中情况:

Comments 2 条评论
Warning: Trying to access array offset on value of type null in /www/wwwroot/wordpress/wp-content/themes/Sakurairo-main/functions.php on line 367
Warning: Trying to access array offset on value of type null in /www/wwwroot/wordpress/wp-content/themes/Sakurairo-main/functions.php on line 367
Warning: Trying to access array offset on value of type null in /www/wwwroot/wordpress/wp-content/themes/Sakurairo-main/functions.php on line 368
Warning: Trying to access array offset on value of type null in /www/wwwroot/wordpress/wp-content/themes/Sakurairo-main/functions.php on line 368
底部加载耗时,查询次数,内存使用是主题自带的,还是什么插件
Warning: Trying to access array offset on value of type null in /www/wwwroot/wordpress/wp-content/themes/Sakurairo-main/functions.php on line 367
Warning: Trying to access array offset on value of type null in /www/wwwroot/wordpress/wp-content/themes/Sakurairo-main/functions.php on line 367
Warning: Trying to access array offset on value of type null in /www/wwwroot/wordpress/wp-content/themes/Sakurairo-main/functions.php on line 368
Warning: Trying to access array offset on value of type null in /www/wwwroot/wordpress/wp-content/themes/Sakurairo-main/functions.php on line 368
@2130742393 Sakurairo主题自带的