tekod/wp-cache-controller 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tekod/wp-cache-controller

Composer 安装命令:

composer require tekod/wp-cache-controller

包简介

WordPress library for caching arbitrary data with automatic invalidation.

README 文档

README

License: MIT Issues

WpCacheController

WordPress library for caching arbitrary data with automatic invalidation

WpCacheController is WordPress library for caching arbitrary data with automatic invalidation. It is framework-agnostic so no other packages are needed for its proper operation.

This lib constantly updates log and statistics records to inform an administrator about cache usage.

There is admin dashboard settings page where administrator can enable/disable caching function and see log records and statistics.

Typical usage for this library is to substitute code blocks that have to access database several times to prepare HTML content, for example: navigation block, category tree, footer, the latest blog posts block, related products block,...

Usage:

Put this in "functions.php" of yours theme to initialize the controller where parameter is path to configuration file:

use Tekod\WpCacheController\CacheController;
require_once 'inc/WpCacheController/CacheController.php';  // optional if you use some autoloader
CacheController::Init(__DIR__.'/config/cachecontroller.config.php');

Example of configuration is part of this lib. It is highly recommended to clone (and rename) configuration file outside of lib directory and edit content there, just like in code above. That way you can safely update library without losing configuration.

This will echo HTML content identified as "product menu" from cache or include template if not:

CacheController::Profile('eCommerce')->Output('product menu', function() {
    get_template_part('template-parts/woocommerce_product_menu');
});

Here is how to pass parameter to inner function (closure) to create a dynamic identifier:

CacheController::Profile('Shop')->Output('product-page-'.$ProductID, function() use ($ProductID) {
     $Product= new MyProduct($ProductID);
     $Title= $Product->GetTitle();
     $Image= $Product->GetImage();
     include 'shop/single-product.php';
});

Instead of echoing content use "Get()" to just return arbitrary data, typical use case is to replace fetching values from a database with heavy SQL queries

$Data= CacheController::Profile('Movies')->Get('full-movie-data-'.$ID, function() use ($ID) {
     return [
         'Movie' => get_post($ID),
         'Genres' => get_posts(['posts_per_page' => -1, 'post_type' => 'genre', 'tax_query' => [.....
         'Actors' => get_posts(['posts_per_page' => -1, 'post_type' => 'actor', 'tax_query' => [.....
         'Photos' => get_posts(['posts_per_page' => -1, 'post_type' => 'photo', 'tax_query' => [.....
         ....
     ];
});

Note: identifiers must contain only filename-safe chars (regex: "A-Za-z0-9~_!&= |.-+") easiest method to ensure that is to pass it through md5 func, like:

CacheController::Profile('IMDB')->Get(md5($URL), function() {...

3rd parameter

Methods Get and Output has 3rd parameter "OnCacheHit" where you can put code block (closure) that should be executed if content is returned from cache (meaning main closure was not executed).

Example for use case using this feature can be caching template block containing ContactForm7 shortcode because beside echoing HTML this plugin relies on actions to include some javascript. Using 3rd parameter you can execute all that side-effects to simulate normal environment and ensure plugin proper operation, in this case: echoing missing javascript code.

MVC themes

This library is perfect for MVC style themes, you can wrap all getters from "model" with closure and fetch them via Get() method, just like in last usage example. Pure simplicity: gather all data from all sources and cache them in single call.

Security issues

If you have found a security issue, please contact the author directly at office@tekod.com.

tekod/wp-cache-controller 适用场景与选型建议

tekod/wp-cache-controller 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.29k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 03 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「data」 「cache」 「wordpress」 「caching」 「wp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 tekod/wp-cache-controller 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-07