• 安装redis

    apt-get update
    apt-get install redis redis-server php-redis

    编辑 /etc/redis/redis.conf 文件,添加

    maxmemory 256mb
    maxmemory-policy allkeys-lfu

    重启服务

    systemctl restart redis-server
    systemctl restart php7.4-fpm
    systemctl restart apache2

    编辑wp-config.php文件添加

    define( 'WP_CACHE_KEY_SALT', 'zuoridangnian.com' );
    define( 'WP_CACHE', true );

    安装Redis Object Cache 插件,点击开启缓存即可

    下面查看一下效果

    WP有个 Query Monitor 插件,可以查看一个页面的查询次数

    未开启Redis Object Cache时,我的后台页面和首页查询次数是这样的

    分别是68个查询和56个查询

    开启后减少为32和25,大约节约一半的查询次数