{"id":37008103,"url":"https://github.com/loophp/memoize","last_synced_at":"2026-01-14T00:49:40.317Z","repository":{"id":54992056,"uuid":"104074893","full_name":"loophp/memoize","owner":"loophp","description":"Memoize a closure.","archived":true,"fork":false,"pushed_at":"2024-10-09T14:19:58.000Z","size":94,"stargazers_count":12,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2026-01-07T02:21:01.320Z","etag":null,"topics":["cache","educational","memoization","memoize","memoizer"],"latest_commit_sha":null,"homepage":"https://not-a-number.io/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loophp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":null,"code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"drupol"}},"created_at":"2017-09-19T12:56:29.000Z","updated_at":"2025-01-09T09:52:11.000Z","dependencies_parsed_at":"2025-11-15T19:00:24.814Z","dependency_job_id":null,"html_url":"https://github.com/loophp/memoize","commit_stats":{"total_commits":80,"total_committers":4,"mean_commits":20.0,"dds":0.1875,"last_synced_commit":"1b6943b54d4f95f52114b97835ac5c9e9e61087d"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/loophp/memoize","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loophp%2Fmemoize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loophp%2Fmemoize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loophp%2Fmemoize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loophp%2Fmemoize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loophp","download_url":"https://codeload.github.com/loophp/memoize/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loophp%2Fmemoize/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407023,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","educational","memoization","memoize","memoizer"],"created_at":"2026-01-14T00:49:39.458Z","updated_at":"2026-01-14T00:49:40.305Z","avatar_url":"https://github.com/loophp.png","language":"PHP","funding_links":["https://github.com/sponsors/drupol","https://www.paypal.me/drupol"],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version][latest stable version]][packagist]\n [![GitHub stars][github stars]][packagist]\n [![Total Downloads][total downloads]][packagist]\n [![GitHub Workflow Status][github workflow status]][github actions]\n [![Scrutinizer code quality][code quality]][code quality link]\n [![Type Coverage][type coverage]][sheperd type coverage]\n [![Code Coverage][code coverage]][code quality link]\n [![License][license]][packagist]\n [![Donate!][donate github]][github sponsor]\n [![Donate!][donate paypal]][paypal sponsor]\n\n# PHP Memoize\n\n## Description\n\nMemoizer class for callable.\n\nFrom wikipedia:\n\u003e In computing, memoization is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.\n\nThis library help you to memoize callable or closures.\n\n## Features\n\n* Provides a Memoizer class.\n* Immutable.\n* Stateless.\n\n## Installation\n\nWith composer:\n\n`composer require loophp/memoize`\n\n## Usage\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App;\n\ninclude 'vendor/autoload.php';\n\nuse Closure;\nuse Generator;\nuse loophp\\memoize\\Memoizer;\n\n$fibonacci = static function (int $number) use (\u0026$fibonacci): int {\n    return (1 \u003e= $number) ?\n        $number :\n        $fibonacci($number - 1) + $fibonacci($number - 2);\n};\n\n$fibonacciMemoized = static function (int $number) use (\u0026$fibonacciMemoized): int {\n    return (1 \u003e= $number) ?\n        $number :\n        $fibonacciMemoized($number - 1) + $fibonacciMemoized($number - 2);\n};\n$fibonacciMemoized = Memoizer::fromClosure($fibonacciMemoized);\n\nfunction bench(Closure $closure, ...$arguments): array\n{\n    $eval = static function (Closure $closure, ...$arguments): Generator {\n        yield microtime(true);\n        yield $closure(...$arguments);\n        yield microtime(true);\n    };\n\n    $result = iterator_to_array($eval($closure, ...$arguments));\n\n    return [\n        $result[1],\n        $result[2] - $result[0],\n    ];\n}\n\nvar_dump(sprintf('[return: %s] [duration: %s]', ...bench($fibonacci, 30))); // ~3 seconds\nvar_dump(sprintf('[return: %s] [duration: %s]', ...bench($fibonacciMemoized, 30))); // ~0.0003 seconds\n```\n\n## Code style, code quality, tests and benchmarks\n\nThe code style is following [PSR-12](https://www.php-fig.org/psr/psr-12/) plus a set of custom rules, the package [drupol/php-conventions](https://github.com/drupol/php-conventions)\nis responsible for this.\n\nEvery time changes are introduced into the library, [Github CI](https://github.com/drupol/memoize/actions) run the tests and the benchmarks.\n\nThe library has tests written with [PHPSpec](http://www.phpspec.net/).\nFeel free to check them out in the `spec` directory. Run `composer phpspec` to trigger the tests.\n\n[PHPInfection](https://github.com/infection/infection) is used to ensure that your code is properly tested, run `composer infection` to test your code.\n\n## Contributing\n\nSee the file [CONTRIBUTING.md](.github/CONTRIBUTING.md) but feel free to contribute to this library by sending Github pull requests.\n\n[latest stable version]: https://img.shields.io/packagist/v/loophp/memoize.svg?style=flat-square\n[packagist]: https://packagist.org/packages/loophp/memoize\n\n[github stars]: https://img.shields.io/github/stars/loophp/memoize.svg?style=flat-square\n\n[total downloads]: https://img.shields.io/packagist/dt/loophp/memoize.svg?style=flat-square\n\n[github workflow status]: https://img.shields.io/github/workflow/status/loophp/memoize/Continuous%20Integration?style=flat-square\n[github actions]: https://github.com/loophp/memoize/actions\n\n[code quality]: https://img.shields.io/scrutinizer/quality/g/loophp/memoize/master.svg?style=flat-square\n[code quality link]: https://scrutinizer-ci.com/g/loophp/memoize/?branch=master\n\n[type coverage]: https://shepherd.dev/github/loophp/memoize/coverage.svg\n[sheperd type coverage]: https://shepherd.dev/github/loophp/memoize\n\n[code coverage]: https://img.shields.io/scrutinizer/coverage/g/loophp/memoize/master.svg?style=flat-square\n[code quality link]: https://img.shields.io/scrutinizer/quality/g/loophp/memoize/master.svg?style=flat-square\n\n[license]: https://img.shields.io/packagist/l/loophp/memoize.svg?style=flat-square\n\n[donate github]: https://img.shields.io/badge/Sponsor-Github-brightgreen.svg?style=flat-square\n[github sponsor]: https://github.com/sponsors/drupol\n\n[donate paypal]: https://img.shields.io/badge/Sponsor-Paypal-brightgreen.svg?style=flat-square\n[paypal sponsor]: https://www.paypal.me/drupol\n\n[phpspec]: http://www.phpspec.net/\n[grumphp]: https://github.com/phpro/grumphp\n[infection]: https://github.com/infection/infection\n[phpstan]: https://github.com/phpstan/phpstan\n[psalm]: https://github.com/vimeo/psalm\n[changelog-md]: https://github.com/loophp/memoize/blob/master/CHANGELOG.md\n[git-commits]: https://github.com/loophp/memoize/commits/master\n[changelog-releases]: https://github.com/loophp/memoize/releases\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floophp%2Fmemoize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floophp%2Fmemoize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floophp%2Fmemoize/lists"}