dereuromark/cakephp-url-cache 问题修复 & 功能扩展

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

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

dereuromark/cakephp-url-cache

Composer 安装命令:

composer require dereuromark/cakephp-url-cache

包简介

CakePHP plugin to speed up URL reverse lookup

README 文档

README

Build Status Latest Stable Version Coverage Status Minimum PHP Version License Total Downloads

For CakePHP 2.x

Whenever you use $this->Html->link() in your CakePHP views the CakePHP Router has to scan through all your routes until it finds a match. This can be slow if you have a lot of links on a page or use a lot of custom routes. By adding this code to your AppHelper the URLs are cached, speeding up requests. The cache settings follow the same rules as the other CakePHP core cache settings. If debug is set to greater than 0 the cache expires in 10 seconds. With debug at 0 the cache is good for 999 days.

Instructions

  1. Download the plugin to app/Plugin/UrlCache manually or include it via composer.

  2. Put at the top of your app/View/Helper/AppHelper.php:

    App::uses('UrlCacheAppHelper', 'UrlCache.View/Helper');
  3. Load and activate Plugin in app/Config/bootstrap.php:

    CakePlugin::load('UrlCache');
    
    Configure::write('UrlCache.active', true);
  4. Have your AppHelper extend UrlCacheAppHelper instead of Helper:

    class AppHelper extends UrlCacheAppHelper {
        ...
    }
  5. That's it! Just continue using $this->Html->link() or $this->Html->url() as you usually do.

Configuration

By default all the cache will be stored in one file. This is only recommended for sites with not many links. If your site has a ton of unique URLs you don't want to store them all in one giant cache which would need to be loaded each request. So in case you have a large amount of links on specific pages, and if they contain more than just the main URL fragments (prefix, plugin, controller, action) like with pagination you can set the option Configure::write('UrlCache.pageFiles', true) and each page will additionally keep a separate cache for those unique URLs. Only the controller/action URLs without named or passed params will then be stored in the global cache.

There is also a Configure::write('UrlCache.verbosePrefixes', true) param. It is useful if you defined some prefixes in your core.php like Configure::write('Routing.prefixes', ['admin']); and if you mainly still use the old 1.2/1.3 syntax for prefixes:

'admin' => true/false

instead of

'prefix' => 'admin'

The latter is more future proof, though.

Debugging

With the de-facto-standard debugging tool DebugKit you can enable a toolbar panel that allows you to see how many links have been used and/or added per page view. To enable it, you can add it to your $components configuration:

public $components = ['DebugKit.Toolbar' => ['panels' => ['UrlCache.UrlCache']]];

Benchmark

With a little sample script you can at least approximate the improvement for your (custom) routes:

// In your view ctp:
$timeStart = microtime(true);

$url = ['controller' => 'posts', 'action' => 'view'];
for ($i = 0; $i < 10000; $i++) {
	$u = $url;
	$u[] = $i;
	$link = $this->Html->link($i, $u);
}

$timeEnd = microtime(true);
$time = $timeEnd - $timeStart;
debug($time);

With the first request with my test it was 9 seconds, the second hit only 1 second. So in overall the speed improvement can be around 10x faster. It really depends on how dynamic your pages and URLs are, though. And the above 10000 links is not a realistic scenario, so the overall speed improvement compared to the whole dispatcher process will be usually a lot less. So you definitely should look into other bottlenecks, usually the DB, opcode caching, and dispatching speed in general.

dereuromark/cakephp-url-cache 适用场景与选型建议

dereuromark/cakephp-url-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 117.19k 次下载、GitHub Stars 达 24, 最近一次更新时间为 2015 年 03 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 dereuromark/cakephp-url-cache 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 117.19k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 25
  • 点击次数: 27
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-13