PHPackages                             ganglio/memoizer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ganglio/memoizer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ganglio/memoizer
================

Simple PHP Memoizer class

v1.0.4.2(10y ago)020MITPHPPHP &gt;=5.4.0

Since Feb 27Pushed 10y ago1 watchersCompare

[ Source](https://github.com/ganglio/Memoizer)[ Packagist](https://packagist.org/packages/ganglio/memoizer)[ Docs](http://www.github.com/ganglio/Memoizer)[ RSS](/packages/ganglio-memoizer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (8)Used By (0)

Memoizer
========

[](#memoizer)

Simple PHP Memoizer class

[![Latest Stable Version](https://camo.githubusercontent.com/42a886d9f1a60460ada8bf121c6df349d90ff45b294f85b6d3aa2250e0bbe31b/68747470733a2f2f706f7365722e707567782e6f72672f67616e676c696f2f4d656d6f697a65722f762f737461626c65)](https://packagist.org/packages/ganglio/Memoizer)[![Build Status](https://camo.githubusercontent.com/f5684282b0f3feb1ef12f9e47f64be7a98f1ac4dc0e435e7d0d0e31384e69f28/68747470733a2f2f7472617669732d63692e6f72672f67616e676c696f2f4d656d6f697a65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ganglio/Memoizer)[![codecov.io](https://camo.githubusercontent.com/bc8cb48f335acb0761a0dc157c87832d1a854866083a9b72c214ab5d7d4de5c0/687474703a2f2f636f6465636f762e696f2f6769746875622f67616e676c696f2f4d656d6f697a65722f636f7665726167652e7376673f6272616e63683d6d6173746572)](http://codecov.io/github/ganglio/Memoizer?branch=master)[![Code Climate](https://camo.githubusercontent.com/1ce459beba3819a5ff30a92597bb00010de803bf6babfdc94ccde7903ccb3bc9/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f67616e676c696f2f4d656d6f697a65722f6261646765732f6770612e737667)](https://codeclimate.com/github/ganglio/Memoizer)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3c5264d2c98603ef18c03e20ca05e174caa451b09bfad78230a430e91f225cce/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f67616e676c696f2f4d656d6f697a65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ganglio/Memoizer/?branch=master)[![License](https://camo.githubusercontent.com/a24051d79e46aa56d54c1236312f93c9b24c561679a20fe1ce74d929641687d5/68747470733a2f2f706f7365722e707567782e6f72672f67616e676c696f2f4d656d6f697a65722f6c6963656e7365)](https://packagist.org/packages/ganglio/Memoizer)

The class allow to encapsulate any callable so that, during the first call (with a given set of arguments), the callable is executed and the return values are stored. At every successive call (with the same set of arguments) the stored value is used instead of invoking the callable again.

Examples
--------

[](#examples)

This is a dumb example with a time variant call just to demonstate the way the memoized function works. If your callable has that kind of behaviour memoizing it is probably not a good idea :D

```
$myFunc = function ($a) {
	return $a * mt_rand();
}

$myMemoizedFunc = new Memoizer($myFunc);

echo "Returns: " . $myMemoizedFunc(3) . "\n";
echo "Returns the same value: " . $myMemoizedFunc(3) . "\n";
```

A time consuming callable can be made more efficient storing the return value for later invokation.

```
$mySlowFunc = function ($a) {
	sleep(5);
	return $a * mt_rand();
}

$myMemoizedSlowFunc = new Memoizer($mySlowFunc);

$st = time();
echo "Returns: " . $myMemoizedSlowFunc(3) . " in: " . (time() - $st);

$st = time();
echo "Returns the same value: " . $myMemoizedSlowFunc(3) . " in basically 0 time: " . (time() - $st);
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

7

Last Release

3720d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5305bcf3bda76fdc9179cd51aac78e79992208ad4414819a814c5d0c3315f75c?d=identicon)[ganglio](/maintainers/ganglio)

---

Top Contributors

[![ganglio](https://avatars.githubusercontent.com/u/498939?v=4)](https://github.com/ganglio "ganglio (9 commits)")

---

Tags

memoize

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ganglio-memoizer/health.svg)

```
[![Health](https://phpackages.com/badges/ganglio-memoizer/health.svg)](https://phpackages.com/packages/ganglio-memoizer)
```

###  Alternatives

[ihor/nspl

Non-standard PHP library (NSPL) - functional primitives toolbox and more

381368.5k](/packages/ihor-nspl)[daveross/functional-programming-utils

Functional Programming utilities for PHP 5.4+

225.2k](/packages/daveross-functional-programming-utils)[dan-da/coinparams

provides crypto currency specific information such as version numbers, DNS seeds, etc, available in JSON format

3551.9k5](/packages/dan-da-coinparams)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
