codingpaws / simple-memoize
This package is abandoned and no longer maintained.
No replacement package was suggested.
Simple trait-based memoization to cache return values
1.2
2022-05-27 07:50 UTC
Requires (Dev)
- phpunit/phpunit: ^9.5
Suggests
- laravel/framework: >=8.0
This package is auto-updated.
Last update: 2024-12-27 13:16:01 UTC
README
codingpaws/simple-memoize
is a PHP library for simple, trait-based
memoization (i.e. caching return values per class). Although many PHP
memoization dependencies exist, there is none that can be used very
easily like this:
use CodingPaws\SimpleMemoize\Memoize;
class Calculator
{
use Memoize;
public function __construct(public int $base) {
}
public function pow10(): int
{
return $this->memoize(fn () => pow(10, $this->exponent));
}
}
$calculator = new Calculator(1234);
$calculator->pow10(); // 3.0913151596972
$calculator->pow10(); // will not be calculated again