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.5.0(2mo ago)2515.9M↓28.3%[2 PRs](https://github.com/beste/in-memory-cache-php/pulls)6MITPHPPHP ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Dec 8Pushed 1w ago1 watchersCompare

[ Source](https://github.com/beste/in-memory-cache-php)[ Packagist](https://packagist.org/packages/beste/in-memory-cache)[ RSS](/packages/beste-in-memory-cache/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (7)Dependencies (23)Versions (12)Used By (6)

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

63

—

FairBetter than 99% of packages

Maintenance93

Actively maintained with recent releases

Popularity56

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity67

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

Recently: every ~160 days

Total

7

Last Release

68d ago

PHP version history (4 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

1.5.0PHP ~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

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k373.5M3.3k](/packages/symfony-cache)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[laminas/laminas-cache

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

1077.3M154](/packages/laminas-laminas-cache)[tedivm/stash

The place to keep your cache.

9614.9M128](/packages/tedivm-stash)[cache/adapter-common

Common classes for PSR-6 adapters

11125.4M38](/packages/cache-adapter-common)

PHPackages © 2026

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