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 1w ago

READMEChangelog (10)Dependencies (2)Versions (14)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

32

—

LowBetter than 69% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

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

1369d 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

[robmorgan/phinx

Phinx makes it ridiculously easy to manage the database migrations for your PHP app.

4.5k49.7M494](/packages/robmorgan-phinx)[pocketmine/pocketmine-mp

A server software for Minecraft: Bedrock Edition written in PHP

3.6k79.3k91](/packages/pocketmine-pocketmine-mp)[danog/madelineproto

Async PHP client API for the telegram MTProto protocol.

3.5k920.5k24](/packages/danog-madelineproto)[buggregator/trap

A simple and powerful tool for debugging PHP applications.

2742.3M73](/packages/buggregator-trap)[phptg/bot-api

PHP library for working with Telegram API

12819.7k8](/packages/phptg-bot-api)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)

PHPackages © 2026

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