定制 evista/pj-page-cache-red 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

evista/pj-page-cache-red

Composer 安装命令:

composer require evista/pj-page-cache-red

包简介

Redis backed page cache

README 文档

README

A Redis-backed full page caching plugin for WordPress, extremely flexible and fast. Requires a running Redis server, a Redis client package (currently only cheprasov/php-redis-client is supported), and Composer

Latest Version on Packagist Build Status Total Downloads

Requirements

Redis server:

sudo apt-get install redis-server

This fork of the original package is being actively refactored to use a Redis package instead of the Redis PECL extension and to add some test coverage. My most important plan is to add an interface to hint the current dependency injection, and add more tests.

Make sure your Redis server has enough memory allocated to store your cached pages. The plugin compresses cached pages using gzip to lower memory usage. We recommend anywhere from 16 mb allocated just for page caching. Increase according to your hit-rate. We also recommend disabling flushing Redis cache to disk, and the allkeys-lru eviction policy to ensure the server can make more room for new cached pages by evicting older ones. Here is a sample extract from the redis.conf file:

maxmemory 16m
maxmemory-policy allkeys-lru

Don't forget to restart the Redis server after making changes to the configuration file.

Installing the WordPress Plugin

Install the plugin via composer then activate it. It adds the advanced-cache.php file as a symlink into the wp-contents folder:

composer require evista/pj-page-cache-red

Enable page caching in your WordPress wp-config.php file with a constant:

define( 'WP_CACHE', true );
define('REDIS_CACHE', true);

Set up some important Redis options (both has defaults):

define('REDIS_CACHE_TTL', 3000);
define('REDIS_DB', 10);
define('REDIS_HOST', getenv('REDIS_HOST') ?: '127.0.0.1');
define('REDIS_PORT', getenv('REDIS_PORT') ?: 6379);

Try visiting your site in incognito mode or cURL, you should see an X-Pj-Cache- header:

curl -v https://example.org -o /dev/null
< X-Pj-Cache-Status: hit

That's it!

Purging Cache

By default, this plugin will expire posts (pages, cpt) whenever they are published or updated, including the front page and any RSS feeds. You may also choose to expire certain URLs or cache flags at certain other events. For example:

// Expire cache by post ID (argument can be an array of post IDs):
Redis_Page_Cache::clear_cache_by_post_id( $post->ID );

// Expire cache by URL (argument can be an array of URLs):
Redis_Page_Cache::clear_cache_by_url( 'https://example.org/secret-page/' );

// Expire cache by flag (argument can be an array):
Redis_Page_Cache::clear_cache_by_flag( array( 'special-flag' ) );

Wait, what the heck are flags?

Redis Page Cache stores a set of flags with each cached item. These flags allow the plugin to better target cached entries when flushing. For example, a single post can have multiple URLs (cache buckets, request variables, etc.) and thus, multiple cache keys:

https://example.org/?p=123
https://example.org/post-slug/
https://example.org/post-slug/page/2/
https://example.org/post-slug/?show_comments=1

These URLs will have unique cache keys and contents, but Redis Page Cache will flag them with a post ID, so you can easily purge all three items if you know the flag:

$post_id = 123;
$flag = sprintf( 'post:%d:%d', get_current_blog_id(), $post_id );

Redis_Page_Cache::clear_cache_by_flag( $flag );

You can add your own custom flags to requests too:

// Flag all single posts with a tag called my-special-tag:
if ( is_single() && has_tag( 'my-special-tag' ) ) {
    Redis_Page_Cache::flag( 'my-special-tag' );
}

// And whenever you need to:
Redis_Page_Cache::clear_cache_by_flag( 'my-special-tag' );

Note that all the clear cache methods expire (but don't delete) cache by default. If you're running in an environment where background cache regeneration is available, an expired flag will cause that background regeneration while serving a stale copy to the visitor. If this is not the desired behavior, you can use the optional $expire argument in the clear cache methods (set to false) to force delete a flag/URL.

Support

If you need help installing and configuring this plugin, feel free to reach out to us via e-mail: sera.balint@e-vista.hu.

evista/pj-page-cache-red 适用场景与选型建议

evista/pj-page-cache-red 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 148 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 evista/pj-page-cache-red 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 evista/pj-page-cache-red 我们能提供哪些服务?
定制开发 / 二次开发

基于 evista/pj-page-cache-red 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 148
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 24
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-19