crodas / memorandum
此包的最新版本(v0.2.1)没有可用的许可证信息。
一个增强版的神奇记忆化函数
v0.2.1
2019-12-23 21:06 UTC
Requires
- php: >=7.0
This package is auto-updated.
Last update: 2024-08-25 16:59:11 UTC
README
一个增强版的记忆化函数。
动机
记忆化存储昂贵的函数调用的结果,当相同的输入再次出现时返回缓存的结果。
此库存储函数的结果。如果函数的任何参数是文件或文件夹,则结果将在这些文件或文件夹中的任何文件被修改或删除之前被视为有效。
涉及I/O的任何函数都注定要慢,这就是为什么Memorandum通过仅在必要时处理事物来加速事物。
用法
<?php $function = memo(function($file) { sleep(10); return 'cached ouptut:' . $file; }); $result = $function(__DIR__); $result = $function(__DIR__); // The function would be called once, and the output // will be remembered until a new file is added to __DIR__ // or another file is removed.