codingpaws / simple-memoize
Simple trait-based memoization to cache return values
Installs: 2 578
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
pkg:composer/codingpaws/simple-memoize
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