PHPackages                             beste/in-memory-cache - 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. beste/in-memory-cache

ActiveLibrary[Caching](/categories/caching)

beste/in-memory-cache
=====================

A PSR-6 In-Memory cache that can be used as a fallback implementation and/or in tests.

1.4.0(7mo ago)2512.2M↑28.4%[1 PRs](https://github.com/beste/in-memory-cache-php/pulls)5MITPHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Dec 8Pushed 2w ago1 watchersCompare

[ Source](https://github.com/beste/in-memory-cache-php)[ Packagist](https://packagist.org/packages/beste/in-memory-cache)[ GitHub Sponsors](https://github.com/jeromegamez)[ RSS](/packages/beste-in-memory-cache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (12)Versions (9)Used By (5)

PSR-6 In-Memory Cache
=====================

[](#psr-6-in-memory-cache)

A [PSR-6](https://www.php-fig.org/psr/psr-6/) In-Memory cache that can be used as a default implementation and in tests.

[![Current version](https://camo.githubusercontent.com/33bc0bd584f513d6cd184e1491941b26644cc382cffce2745ca8bdea9f1f9b79/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62657374652f696e2d6d656d6f72792d63616368652e7376673f6c6f676f3d636f6d706f736572)](https://packagist.org/packages/beste/in-memory-cache)[![Packagist PHP Version Support](https://camo.githubusercontent.com/55a8b4a04c5af39bdd6551f9fcb132c64def169d65616ea798e0a6d975cb6edc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f62657374652f696e2d6d656d6f72792d6361636865)](https://packagist.org/packages/beste/in-memory-cache)[![Monthly Downloads](https://camo.githubusercontent.com/9760591a3ee4490d08ebd65e9221b665ece94041832aee56eed40f3094f3c2c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f62657374652f696e2d6d656d6f72792d63616368652e737667)](https://packagist.org/packages/beste/in-memory-cache/stats)[![Total Downloads](https://camo.githubusercontent.com/928f58276be25bae49d4efd6ab2fe44bdf3eccfc6912dcb7e9a827249a1d1b26/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62657374652f696e2d6d656d6f72792d63616368652e737667)](https://packagist.org/packages/beste/in-memory-cache/stats)[![Tests](https://github.com/beste/in-memory-cache-php/actions/workflows/tests.yml/badge.svg)](https://github.com/beste/in-memory-cache-php/actions/workflows/tests.yml)

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

[](#installation)

```
composer require beste/in-memory-cache
```

Usage
-----

[](#usage)

```
use Beste\Cache\InMemoryCache;

$cache = new InMemoryCache();

$item = $cache->getItem('key');

assert($item->isHit() === false);
assert($item->get() === null);

$item->set('value');
$cache->save($item);

// Later...

$item = $cache->getItem('key');

assert($item->isHit() === true);
assert($item->get() === 'value');
```

You can also provide your own [PSR-20](https://www.php-fig.org/psr/psr-20/) clock implementation, for example a frozen clock for testing, for example from the [`beste/clock` library](https://github.com/beste/clock).

```
use Beste\Clock\FrozenClock;
use Beste\Cache\InMemoryCache;

$clock = FrozenClock::fromUTC()
$cache = new InMemoryCache();

$item = $cache->getItem('key');
$item->set('value')->expiresAfter(new DateInterval('PT5M'));
$cache->save($item);

$clock->setTo($clock->now()->add(new DateInterval('PT2M')));
assert($cache->getItem('key')->isHit() === true);

$clock->setTo($clock->now()->add(new DateInterval('PT5M')));
assert($cache->getItem('key')->isHit() === false);
```

Running tests
-------------

[](#running-tests)

```
composer test
```

License
-------

[](#license)

This project is published under the [MIT License](LICENSE).

###  Health Score

59

—

FairBetter than 99% of packages

Maintenance82

Actively maintained with recent releases

Popularity55

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 78.1% 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 ~132 days

Recently: every ~144 days

Total

6

Last Release

231d ago

PHP version history (3 changes)1.0.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0

1.3.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0

1.4.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8685cf532053a084f1eade7b7da00a512c02676e65f1f1bdec73d4978030a47d?d=identicon)[jeromegamez](/maintainers/jeromegamez)

---

Top Contributors

[![jeromegamez](https://avatars.githubusercontent.com/u/67554?v=4)](https://github.com/jeromegamez "jeromegamez (25 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")[![lubiana](https://avatars.githubusercontent.com/u/1454479?v=4)](https://github.com/lubiana "lubiana (1 commits)")

---

Tags

cachephppsr-6cachepsr-6beste

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/beste-in-memory-cache/health.svg)

```
[![Health](https://phpackages.com/badges/beste-in-memory-cache/health.svg)](https://phpackages.com/packages/beste-in-memory-cache)
```

###  Alternatives

[laminas/laminas-cache

Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output

1076.9M130](/packages/laminas-laminas-cache)[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[cache/adapter-common

Common classes for PSR-6 adapters

11124.4M38](/packages/cache-adapter-common)[cache/hierarchical-cache

A helper trait and interface to your PSR-6 cache to support hierarchical keys.

6016.1M11](/packages/cache-hierarchical-cache)[cache/filesystem-adapter

A PSR-6 cache implementation using filesystem. This implementation supports tags

705.8M82](/packages/cache-filesystem-adapter)[cache/array-adapter

A PSR-6 cache implementation using a php array. This implementation supports tags

548.3M151](/packages/cache-array-adapter)

PHPackages © 2026

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