PHPackages                             kenny1911/php-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. kenny1911/php-memoizer

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

kenny1911/php-memoizer
======================

0.1.0(6mo ago)0625MITPHPPHP ^8.1

Since Nov 28Pushed 6mo agoCompare

[ Source](https://github.com/Kenny1911/php-memoizer)[ Packagist](https://packagist.org/packages/kenny1911/php-memoizer)[ RSS](/packages/kenny1911-php-memoizer/feed)WikiDiscussions 0.1 Synced 3w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

PHP Memoizer
============

[](#php-memoizer)

\[English\]\[[Русский](./README-RU.md)\]

A library for memoizing function results in PHP. Allows caching function and method call results for performance optimization.

Installation
------------

[](#installation)

```
composer require kenny1911/php-memoizer
```

Quick Start
-----------

[](#quick-start)

### Initialization

[](#initialization)

```
use Kenny1911\Memoizer\Cache\InMemoryCache;
use Kenny1911\Memoizer\Memoizer;
use Kenny1911\Memoizer\Normalizer\SimpleNormalizer;

$memoizer = new Memoizer(
    normalizer: new SimpleNormalizer(),
    cache: new InMemoryCache(),
);
```

### Usage in Class

[](#usage-in-class)

```
final readonly class Calculator
{
    public function __construct(
        private Memoizer $memoizer,
    ) {}

    public function sum(int $a, int $b): int
    {
        return $this->memoizer->memoize([__METHOD__, \func_get_args()], function() use ($a, $b): int {
            return $a + $b;
        });
    }
}

$calculator = new Calculator($memoizer);

$calculator->sum(1, 2); // Calculates value: 3
$calculator->sum(1, 2); // Returns memoized value: 3

$calculator->sum(3, 4); // Calculates value: 7
```

Components
----------

[](#components)

### Memoizer

[](#memoizer)

The main class for memoization. Accepts two parameters:

- `normalizer` - normalizer for creating cache keys
- `cache` - cache implementation

### Normalizers

[](#normalizers)

#### SimpleNormalizer

[](#simplenormalizer)

Converts arguments to a string key using the standard PHP `serialize()` function. Suitable for most cases.

### Cache

[](#cache)

#### InMemoryCache

[](#inmemorycache)

Stores data in memory during script execution.

Customization
-------------

[](#customization)

To customize the memoizer, you can write and use your own implementation of a normalizer (interface `Kenny1911\Memoizer\Normalizer\Normalizer`) and/or cache (interface `Kenny1911\Memoizer\Cache\Cache`).

Recommendations
---------------

[](#recommendations)

1. **Use unique keys** - include the method name and all relevant parameters in the key
2. **Avoid memoizing side effects** - memoization is only suitable for pure functions
3. **Consider memory usage** - especially when using InMemoryCache
4. **Test performance** - make sure memoization actually provides benefits

License
-------

[](#license)

MIT

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance66

Regular maintenance activity

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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

2

Last Release

208d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c929378f19c1e2e6a9525debcf490ec49c991a3d1ac6133e3c9fa45cef184102?d=identicon)[Kenny1911](/maintainers/Kenny1911)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mattwright/urlresolver

PHP class that attempts to resolve URLs to a final, canonical link.

66169.0k](/packages/mattwright-urlresolver)[stuttter/wp-user-profiles

A sophisticated way to edit users in WordPress

11119.5k1](/packages/stuttter-wp-user-profiles)[viest/php-ext-xlswriter-ide-helper

PHP Extension Xlswriter IDE Helper

16497.1k32](/packages/viest-php-ext-xlswriter-ide-helper)[smile/module-custom-entity-product-link

Smile - Custom Entity Product link Module

3269.9k1](/packages/smile-module-custom-entity-product-link)

PHPackages © 2026

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