PHPackages                             tonybogdanov/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. tonybogdanov/memoize

ActiveLibrary[Caching](/categories/caching)

tonybogdanov/memoize
====================

Object &amp; class-level in-memory caching

v2.3(3y ago)04.3k[1 PRs](https://github.com/TonyBogdanov/memoize/pulls)1MITPHP

Since Feb 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/TonyBogdanov/memoize)[ Packagist](https://packagist.org/packages/tonybogdanov/memoize)[ RSS](/packages/tonybogdanov-memoize/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (13)Used By (1)

Object &amp; class-level in-memory caching
==========================================

[](#object--class-level-in-memory-caching)

[![Latest Stable Version](https://camo.githubusercontent.com/8c118ea59d27ab9b8c4c6b0f8d80a6f1fcf316c9bf7435368ac5ce9968ba78e5/68747470733a2f2f706f7365722e707567782e6f72672f746f6e79626f6764616e6f762f6d656d6f697a652f762f737461626c65)](https://packagist.org/packages/tonybogdanov/memoize)[![License](https://camo.githubusercontent.com/74fcaa73b63d9303c28a287aaad6ec8ca1fd3caa6890c356f7f6b32e351b9c64/68747470733a2f2f706f7365722e707567782e6f72672f746f6e79626f6764616e6f762f6d656d6f697a652f6c6963656e7365)](https://packagist.org/packages/tonybogdanov/memoize)[![Build](https://github.com/tonybogdanov/memoize/workflows/build/badge.svg)](https://github.com/tonybogdanov/memoize/workflows/build/badge.svg)[![Coverage](https://camo.githubusercontent.com/13fcf64baf43b7e7ba0f649638938f21619b79a5582ad13f18bc74aa1b443ce2/687474703a2f2f746f6e79626f6764616e6f762e6769746875622e696f2f6d656d6f697a652f636f7665726167652e737667)](http://tonybogdanov.github.io/memoize/index.html)

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

[](#installation)

```
composer require tonybogdanov/memoize:^2.0
```

Usage
-----

[](#usage)

### Per-Object Memoization

[](#per-object-memoization)

```
class ClassUsingCaching {
    use \TonyBogdanov\Memoize\Traits\MemoizeTrait;

    public function getObjectLevelCachedThing() {
        return $this->memoize( __METHOD__, function () {
            return 'thing'; // heavy code that needs to run only once per object instance.
        } );
    }
}
```

You can also manually remove memoized values:

```
$object->unmemoize( 'key' );
```

You can even check if a memoized value exists without retrieving it (even if it's `null`):

```
$object->isMemoized( 'key' );
```

### Per-Class Memoization

[](#per-class-memoization)

```
class ClassUsingCaching {
    use \TonyBogdanov\Memoize\Traits\MemoizeTrait;

    public static function getClassLevelCachedThing() {
        return static::memoizeStatic( __METHOD__, function () {
            return 'thing'; // heavy code that needs to run only once per class.
        } );
    }
}
```

You can also manually remove memoized values:

```
StaticClass::unmemoizeStatic( 'key' );
```

You can even check if a memoized value exists without retrieving it (even if it's `null`):

```
StaticClass::isMemoizedStatic( 'key' );
```

### Foreign Objects

[](#foreign-objects)

As of `2.3` you can access and manage the memoized values of foreign objects / classes as well.

```
// per-object
$this->memoizeForeign( $object, 'key', 'value' );
$this->unmemoizeForeign( $object, 'key' );
$this->isMemoizedForeign( $object, 'key' );

// per-class
StaticClass::memoizeStaticForeign( AnotherStaticClass::class, 'key', 'value' );
StaticClass::unmemoizeStaticForeign( AnotherStaticClass::class, 'key' );
StaticClass::isMemoizedStaticForeign( AnotherStaticClass::class, 'key' );
```

### Toggle Memoization

[](#toggle-memoization)

You can toggle memoization globally, which can be useful for testing:

```
Memoize::enable();
Memoize::disable();
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

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 ~99 days

Recently: every ~192 days

Total

11

Last Release

1271d ago

Major Versions

v1.1 → v2.02020-10-08

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/tonybogdanov-memoize/health.svg)](https://phpackages.com/packages/tonybogdanov-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)
