PHPackages                             jdwx/array-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. jdwx/array-cache

ActiveLibrary[Caching](/categories/caching)

jdwx/array-cache
================

A trivial implementation of PSR CacheInterface using an in-memory array.

v1.0.0(2y ago)02.9k↓66.3%2MITPHPPHP &gt;=8.0.0

Since Apr 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/jdwx/array-cache)[ Packagist](https://packagist.org/packages/jdwx/array-cache)[ RSS](/packages/jdwx-array-cache/feed)WikiDiscussions main Synced 3w ago

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

jdwx/array-cache
================

[](#jdwxarray-cache)

This is a trivial implementation of PSR CacheInterface using an in-memory array.

PSR Cache implementations are frequently heavyweight. They can provide a ton of backend options that the user may not need or they might be closely tied to a specific framework that the user doesn't use.

This library is designed to provide a simple, lightweight, and (nearly) dependency-free PSR cache implementation that can be used as a default or placeholder.

For example, this is useful in libraries where a cache is necessary but the implementation will be chosen by the library's users. It can also be used as a development dependency to provide a cache implementation for testing.

The cache has a fully-tested implementation of TTLs with microsecond precision, so if you set something to expire in one second, it will expire in one second, not 0-2 seconds.

The cache can be prepopulated with a JSON string or an array of data. It also supports JSON serialization so you can persist the cache or inspect its contents if necessary. (Also useful for testing.)

Requirements
------------

[](#requirements)

This library requires PHP 8.0 or later. psr/simple-cache is the only runtime dependency.

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

[](#installation)

```
composer require jdwx/array-cache
```

Usage
-----

[](#usage)

The ArrayCache class implements the PSR-16 [CacheInterface](https://www.php-fig.org/psr/psr-16/).

In addition, it can be preloaded with data:

```
use JDWX\ArrayCache\ArrayCache;

$cache = new ArrayCache([ 'foo' => 'bar', 'baz' => 'qux' ]);
```

It can be serialized to JSON, which will preserve the TTLs:

```
$cache = new ArrayCache();
$cache->set( 'foo', 'bar' );
$cache->set( 'baz', 'qux', 5 );
$json = json_encode($cache);
```

It can also be preloaded with JSON:

```
$st = '{"foo":"bar","baz":"qux"}';
$cache = new ArrayCache($st);
assert( $cache->get('foo') === 'bar' );
assert( $cache->get('baz') === 'qux' );

// or

$cache = new ArrayCache();
$cache->set( 'foo', 'bar' );
$cache->set( 'baz', 'qux', 5 );
$cache->set( 'quux', 'corge' );

$st = json_encode($cache);

$cache = new ArrayCache($st);
assert( $cache->get('foo') === 'bar' );
```

Both importing and exporting JSON will drop expired items.

Stability
---------

[](#stability)

This library is stable and has a full suite of unit tests. It is considered suitable for production use within its problem domain. I.e., don't use this where you should be using something like Redis or [symfony/cache](https://symfony.com/components/Cache).

History
-------

[](#history)

This library was created in 2024 because (the otherwise excellent) cache/array-adapter is no longer maintained.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community12

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

797d ago

### Community

Maintainers

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

---

Top Contributors

[![jdwx](https://avatars.githubusercontent.com/u/2722779?v=4)](https://github.com/jdwx "jdwx (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jdwx-array-cache/health.svg)

```
[![Health](https://phpackages.com/badges/jdwx-array-cache/health.svg)](https://phpackages.com/packages/jdwx-array-cache)
```

###  Alternatives

[moonshine/moonshine

Laravel administration panel

1.3k239.9k75](/packages/moonshine-moonshine)[laminas/laminas-cache

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

1067.2M145](/packages/laminas-laminas-cache)[sabre/cache

Simple cache abstraction layer implementing PSR-16

551.3M4](/packages/sabre-cache)[voku/simple-cache

Simple Cache library

322.6M9](/packages/voku-simple-cache)[graham-campbell/bounded-cache

A Bounded TTL PSR-16 Cache Implementation

112.1M10](/packages/graham-campbell-bounded-cache)[neos/cache

Neos Cache Framework

102.1M36](/packages/neos-cache)

PHPackages © 2026

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