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

ActiveLibrary[Caching](/categories/caching)

phpdot/cache
============

PSR-16 cache with pluggable drivers for modern PHP.

v0.1.1(1mo ago)00MITPHPPHP &gt;=8.5

Since Jul 18Pushed 1mo agoCompare

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

READMEChangelogDependencies (23)Versions (6)Used By (0)

phpdot/cache
============

[](#phpdotcache)

PSR-16 cache with pluggable drivers — Redis, File, Array, APCu, Null — and a `remember()`pattern. Standalone.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Drivers](#drivers)
- [PSR-16 Compliance](#psr-16-compliance)
- [Notes](#notes)
- [Architecture](#architecture)
- [Testing](#testing)
- [License](#license)

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

[](#requirements)

RequirementConstraintPHP`>= 8.5``psr/simple-cache``^3.0`ext-redisfor `RedisDriver`ext-apcufor `ApcuDriver`ext-igbinaryoptional — faster serializationInstallation
------------

[](#installation)

```
composer require phpdot/cache
```

Usage
-----

[](#usage)

### Basic

[](#basic)

```
use PHPdot\Cache\Store;
use PHPdot\Cache\Driver\RedisDriver;

$cache = new Store(new RedisDriver($redis, prefix: 'app:'));

$cache->set('user:1', $userData, 3600);
$user = $cache->get('user:1');
$cache->delete('user:1');
$cache->has('user:1'); // false
```

### Remember pattern

[](#remember-pattern)

```
$user = $cache->remember('user:1', 3600, function () use ($db) {
    return $db->table('users')->find(1);
});
// First call: queries DB, caches result
// Subsequent calls: returns from cache

$config = $cache->rememberForever('app:config', fn() => loadConfig());
```

### Swap backends

[](#swap-backends)

```
$cache = new Store(new RedisDriver($redis, prefix: 'app:'));
$cache = new Store(new FileDriver('/var/cache/app'));
$cache = new Store(new ArrayDriver());
$cache = new Store(new ApcuDriver(prefix: 'app:'));
$cache = new Store(new NullDriver());
// Same API, different backend
```

### Batch operations

[](#batch-operations)

```
$cache->setMultiple([
    'user:1' => $user1,
    'user:2' => $user2,
], ttl: 3600);

$users = $cache->getMultiple(['user:1', 'user:2', 'user:3'], default: null);
$cache->deleteMultiple(['user:1', 'user:2']);
```

### LRU eviction (ArrayDriver)

[](#lru-eviction-arraydriver)

```
$cache = new Store(new ArrayDriver(maxItems: 1000));
// Evicts least recently used entry when full
```

### Custom driver

[](#custom-driver)

```
use PHPdot\Cache\DriverInterface;

final class MongoDriver implements DriverInterface
{
    // Implement 8 methods: get, set, delete, clear, has,
    // getMultiple, setMultiple, deleteMultiple
}

$cache = new Store(new MongoDriver($collection));
```

Drivers
-------

[](#drivers)

DriverBackendSerializationSharedUse case`RedisDriver`ext-redisigbinary/serializeYesProduction, distributed`FileDriver`Filesystemigbinary/serializeYes (disk)Single server, no Redis`ArrayDriver`PHP arrayNoneNo (per-worker)Testing, short-lived`ApcuDriver`ext-apcuNone (SHM)Yes (per-server)Single server, fast reads`NullDriver`NoneNoneN/ATesting, disabled cachePSR-16 Compliance
-----------------

[](#psr-16-compliance)

Store implements `Psr\SimpleCache\CacheInterface`:

- Key validation: rejects `{}()/\@:` characters and empty strings
- TTL normalization: accepts `int`, `DateInterval`, or `null`
- Negative TTL treated as expired
- Throws `PHPdot\Cache\Exception\InvalidArgumentException` for invalid keys

Notes
-----

[](#notes)

**`remember()` and null values:** PSR-16 cannot distinguish between "key not found" and "key stores null". If a `remember()` callback returns `null`, the callback will run on every call. Use `false` or a sentinel value instead of `null` for cacheable "empty" results.

Architecture
------------

[](#architecture)

 ```
graph TD
    S[Store] -->|PSR-16| DI[DriverInterface]
    S -->|remember / rememberForever| DI

    DI --> RD[RedisDriver]
    DI --> FD[FileDriver]
    DI --> AD[ArrayDriver]
    DI --> APD[ApcuDriver]
    DI --> ND[NullDriver]
    DI --> CD[Custom Driver]

    RD -->|serialize| SER[Serializer]
    FD -->|serialize| SER

    style S fill:#2d3748,color:#fff
    style DI fill:#4a5568,color:#fff
    style RD fill:#718096,color:#fff
    style FD fill:#718096,color:#fff
    style AD fill:#718096,color:#fff
    style APD fill:#718096,color:#fff
    style ND fill:#718096,color:#fff
    style CD fill:#718096,color:#fff
    style SER fill:#718096,color:#fff
```

      Loading Testing
-------

[](#testing)

The package is standalone-testable:

```
composer install
composer test        # PHPUnit (driver tests skip when ext-redis/ext-apcu are absent)
composer analyse     # PHPStan, level max + strict rules
composer cs-check    # PHP-CS-Fixer
composer check       # All three
```

License
-------

[](#license)

MIT.

**This repository is a read-only mirror**, generated by CI from [phpdot/monorepo](https://github.com/phpdot/monorepo). [Pull requests](https://github.com/phpdot/monorepo/pulls)and [issues](https://github.com/phpdot/monorepo/issues) belong in the monorepo.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance94

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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 ~26 days

Total

5

Last Release

31d ago

PHP version history (3 changes)v1.0.0PHP &gt;=8.3

v1.1.1PHP &gt;=8.4

v0.1.0PHP &gt;=8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/62e82421bda4b5d6ba9a47ba6d88caca060dcd0d1a2862f351f3a97657385db0?d=identicon)[phpdot](/maintainers/phpdot)

---

Top Contributors

[![phpdot](https://avatars.githubusercontent.com/u/252500?v=4)](https://github.com/phpdot "phpdot (4 commits)")[![o3AM](https://avatars.githubusercontent.com/u/252500?v=4)](https://github.com/o3AM "o3AM (2 commits)")

---

Tags

cachesimple-cachepsr-16driver

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sabre/cache

Simple cache abstraction layer implementing PSR-16

551.3M5](/packages/sabre-cache)

PHPackages © 2026

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