承接 antevenio/memoize 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

antevenio/memoize

Composer 安装命令:

composer require antevenio/memoize

包简介

In memory function memoizing, can be capped by total memory consumption and per function ttl.

README 文档

README

Latest Stable Version Total Downloads License Travis build Coverage Status Maintainability

Yet another in memory function memoizing library.

Features

  • Can specify a maximum number of items for the cache to hold.
  • Can place a TTL (time to live) per callable. (meaning that memoize will be returning the callable cached results until the TTL expires, in which case it will call the function again and generate a new cached result)
  • Can override the default callable argument cache indexing with a custom one. (you can reuse a cached callable even passing different arguments if you want to do so)
  • Caches thrown exceptions.

Behaviour

  • When reaching the maximum number of items in cache, it will evict the oldest (first cached) callable first.

Requirements

The following versions of PHP are supported.

  • PHP 5.6
  • PHP 7.0
  • PHP 7.1
  • PHP 7.2
  • PHP 7.3

Installation

composer require antevenio/memoize

Usage

Common code

<?php
require_once('./vendor/autoload.php');

use Antevenio\Memoize\Memoizable;
use Antevenio\Memoize\Memoize;
use Antevenio\Memoize\Cache;

class Toolbox
{
    public function multiply($argument)
    {
        echo "Called with {$argument}\n";

        return $argument * 2;
    }
    
    public function throwException($argument)
    {
        echo "Called with {$argument}\n";

        throw new \Exception($argument);
    }
}

$toolbox = new Toolbox();
$memoize = new Memoize((new Cache())->setEntryLimit(100));

Basic

for ($i = 0; $i < 10; $i++) {
    $result = $memoize->memoize(
        (new Memoizable([$toolbox, 'multiply'], [10]))->withTtl(5)
    );
    echo "Result: $result\n";
    sleep(1);
}

->>>

Called with 10
Result: 20
Result: 20
Result: 20
Result: 20
Result: 20
Called with 10
Result: 20
Result: 20
Result: 20
Result: 20
Result: 20

Changing arguments

for ($i = 0; $i < 10; $i++) {
    $result = $memoize->memoize(
        (new Memoizable([$toolbox, 'multiply'], [$i % 2]))->withTtl(5)
    );
    echo "Result: $result\n";
    sleep(1);
}

->>>

Called with 0
Result: 0
Called with 1
Result: 2
Result: 0
Result: 2
Result: 0
Result: 2
Called with 0
Result: 0
Called with 1
Result: 2
Result: 0
Result: 2

Custom indexing

for ($i = 0; $i < 10; $i++) {
    $result = $memoize->memoize(
        (new Memoizable([$toolbox, 'multiply'], [$i]))->withTtl(5)->withCustomIndex('myFixedIndex')
    );
    echo "Result: $result\n";
    sleep(1);
}

->>>

Called with 0
Result: 0
Result: 0
Result: 0
Result: 0
Result: 0
Called with 5
Result: 10
Result: 10
Result: 10
Result: 10
Result: 10

Exceptions

for ($i = 0; $i < 10; $i++) {
    $result = $memoize->memoize(
        (new Memoizable([$toolbox, 'throwException'], ['foo']))->withTtl(5)
    );
    echo "Result: $result\n";
    sleep(1);
}

->>>

Called with foo
Thrown exception foo
Thrown exception foo
Thrown exception foo
Thrown exception foo
Thrown exception foo
Called with foo
Thrown exception foo
Thrown exception foo
Thrown exception foo
Thrown exception foo
Thrown exception foo

antevenio/memoize 适用场景与选型建议

antevenio/memoize 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.15k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 09 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 antevenio/memoize 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-02