PHPackages                             zeus/memoize - 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. [Caching](/categories/caching)
4. /
5. zeus/memoize

ActiveLibrary[Caching](/categories/caching)

zeus/memoize
============

php memoize library

v1.0.0(3y ago)67MITPHP

Since Oct 27Pushed 3y ago1 watchersCompare

[ Source](https://github.com/diloabininyeri/once)[ Packagist](https://packagist.org/packages/zeus/memoize)[ RSS](/packages/zeus-memoize/feed)WikiDiscussions main Synced 1mo ago

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

### Php memoize

[](#php-memoize)

It does not make different logic each time, it does it in one go and stores the result in memory, so there is no extra operation and time loss when it is called repeatedly, it returns the previous result

**for install with composer**

```
composer require  zeus/memoize
```

**for test**

```
composer test
```

**Basic usage**

```
use function Zeus\Memoize\once;

$closure=function (){
 sleep(1);
 return random_int(1,100);
}

echo once($closure); // same value (it will sleep)
echo once($closure); //same value, it tooks from cache
```

**Parameter usage**

```
use function Zeus\Memoize\once;

 $http = new  Http();

 $closure = function () use ($http) {
     return $http->get('https://www.foobar.com');
 };

 $content = once($closure);
 $content1=once($closure);

 //$content===$content1 =>true
```

**it sensitive to object change**
Via the **&amp;** operator

```
use function Zeus\Memoize\once;

 $linkedin = new  Linkedin();
 $linkedin->setName('dılo sürücü');

 $closure = function () use (&$linkedin) {
     return $http->getProfiles();
 };

$content = once($closure);
$linkedin->setName('abdulkadir sürücü');
$content1=once($closure);

 //$content===$content1 =>false
```

**once wrappers for objects**
OnceWrapper object offers memoize for object,this object is sensitive to change of parameters
usage

```
use Zeus\Memoize\OnceWrapper;

class Random
{

    /**
     * @throws Exception
     */
    public function getInteger(int $start, int $end):int
    {
        return random_int($start, $end);
    }
}

 $random = new Random();
 //let's change of object instance of variable with @phpdoc @var
 /**
 * @var Random $once
 */
 $once = new OnceWrapper($random);

 $first = $once->getInteger(1, 100);
 $second = $once->getInteger(1, 100);
 $third = $once->getInteger(200, 300);

 //$second===$third =>false

 $this->assertEquals($first, $second);
```

> do you notice something, getInteger() method Random object in method, but it's like the method of OnceWrapper object, yes it works just like that

**Custom cache Adapter**
you can use custom cache adapter for customizable cache like redis or memcache .Assuming you have a class called \*\* RedisCacheAdapter\*\*,you can use the "setCacheAdapter" method for this,...

```
class Random
{

    /**
     * @throws Exception
     */
    public function getInteger(int $start, int $end):int
    {
        return random_int($start, $end);
    }
}

$random = new Random();
 //let's change of object instance of variable with @phpdoc @var
 /**
 * @var Random $once
 */
$once = new OnceWrapper($random);
$once->setCacheAdapter(new RedisCacheAdapter());

$first = $once->getInteger(1, 100);
$second = $once->getInteger(1, 100);
```

**once\_wrapper global helper**
useful global function to memoize objects, also added generic class for phpstorm auto complete...

```
use function Zeus\Memoize\once_wrapper;

class Random
{

    /**
     * @throws Exception
     */
    public function getInteger(int $start, int $end):int
    {
        return random_int($start, $end);
    }
}

$first = once_wrapper(new Random())->getInteger(1, 100);
$second = once_wrapper(new Random())->getInteger(1, 100);

var_dump($first===$second); //true
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

1298d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

cachephpstorage

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/zeus-memoize/health.svg)

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

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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