ksamborski/apcu-memo
Composer 安装命令:
composer require ksamborski/apcu-memo
包简介
README 文档
README
#apcumemo PHP library for memoization function results based on it's arguments.
Requirements
You need to have acpu extension installed for php >= 7.0.0
Installation
composer require ksamborski/apcu-memo
Basic usage
Functional paradigm teaches us that pure functions are the way to go. They provide two main features:
- because their result depends only on their arguments they can be easly tested (you don't need any mocks or stubs)
- because they have no side effects they can be easly cached
Consider this example:
use APCuMemo\APCuMemo; function sumrange($a, $b) { return APCuMemo::memoize( function(...$_) use ($a, $b) { return array_reduce(range($a, $b), function ($product, $item) { return $product + $item; }, 1); }, [ 'ttl' => 5 ], "sumrange", $a, $b ); } $start = microtime(true); echo sumrange((int) $_GET['a'], (int) $_GET['b']); $elapsed = microtime(true) - $start; echo " " . ($elapsed * 1000) . " ms";
We have a simple function that sums integers from $a to $b. It can take some time but when we compute it for the first time then we can cache it. Notice the 'ttl' parameter. It is set to 5 seconds and means that if nobody asks us for the same range within 5 seconds it will forget the result. But every request for cached value will reset the ttl. That way we can have only mostly used values in cache.
Let's see it in action. For $a = 1 and $b = 1831233 it will return something like:
1676708065762 283.94412994385 ms
And the followed requests will return:
1676708065762 0.030040740966797 ms
ksamborski/apcu-memo 适用场景与选型建议
ksamborski/apcu-memo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.6k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 10 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ksamborski/apcu-memo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ksamborski/apcu-memo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.6k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-13