PHPackages                             c01l/phpdecorator-memo - 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. c01l/phpdecorator-memo

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

c01l/phpdecorator-memo
======================

Memoization for PHP methods using a Python style Decorator pattern.

1.0.0(4y ago)05MITPHPPHP ^8.0

Since Dec 30Pushed 4y ago1 watchersCompare

[ Source](https://github.com/c01l/phpdecorator-memo)[ Packagist](https://packagist.org/packages/c01l/phpdecorator-memo)[ RSS](/packages/c01l-phpdecorator-memo/feed)WikiDiscussions main Synced today

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

phpdecorator - memo
===================

[](#phpdecorator---memo)

The phpdecorator library extension can be used to store return values in memory depending on its parameters.

This library uses the parameters of a function to build a cache key to cache function call results.

How to use it?
--------------

[](#how-to-use-it)

1. Add `Memo` attribute to a function.
2. Specify the how the cache key is built.

```
class TestClass
{
    #[Memo(["bar"])]
    public function foo(int $bar, int $x): int
    {
        return $x;
    }
}

$obj = new TestClass();
$obj = (new \C01l\PhpDecorator\DecoratorManager())->decorate($obj);

$obj->foo(1,2) // 2
$obj->foo(2,3) // 3
$obj->foo(1,3) // 2, because foo is not really executed again, but the cached version is used
```

Using complex memo keys
-----------------------

[](#using-complex-memo-keys)

The key can be composed of multiple values, by adding more elements to the array:

```
#[Memo(["bar", "x"])]
public function foo($bar, $x) { return $x; }
```

Using no field will result in the function being only called once and different arguments are not considered.

```
#[Memo]
public function foo($bar, $x) { return $x; }

...

$obj->foo(1,2); // 2
$obj->foo(1,3); // 2
$obj->foo(2,5); // 2
$obj->foo(4,6); // 2
```

You can use an arbitrary expression in the key definition.

```
class A {
    public int $x, $y, $z;
    public function getX() { return $x; }
}

...

#[Memo(["bar->z", "bar->getX()"])]
public function foo(A $bar, $x) { return $x; }
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

1646d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17108962?v=4)[c01l](/maintainers/c01l)[@c01l](https://github.com/c01l)

---

Tags

decoratormemoizationphp8

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/c01l-phpdecorator-memo/health.svg)

```
[![Health](https://phpackages.com/badges/c01l-phpdecorator-memo/health.svg)](https://phpackages.com/packages/c01l-phpdecorator-memo)
```

###  Alternatives

[webdevstudios/cpt-core

WordPress Custom Post Type OO wrapper

807.7k1](/packages/webdevstudios-cpt-core)

PHPackages © 2026

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