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. Redis, File, Array, APCu, Null. remember() pattern. Standalone.

v1.1.1(4d ago)05MITPHPPHP &gt;=8.4

Since Apr 3Pushed 2mo agoCompare

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

READMEChangelogDependencies (17)Versions (4)Used By (0)

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

[](#phpdotcache)

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

Install
-------

[](#install)

```
composer require phpdot/cache
```

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 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.

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

[](#requirements)

- PHP &gt;= 8.3
- psr/simple-cache ^3.0
- ext-redis (for RedisDriver)
- ext-apcu (for ApcuDriver)
- ext-igbinary (optional, faster serialization)

License
-------

[](#license)

MIT

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance92

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

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

Every ~44 days

Total

3

Last Release

4d ago

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

v1.1.1PHP &gt;=8.4

### 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 (3 commits)")

---

Tags

rediscachesimple-cachepsr-16fileapcu

###  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

[desarrolla2/cache

Provides an cache interface for several adapters Apc, Apcu, File, Mongo, Memcache, Memcached, Mysql, Mongo, Redis is supported.

1342.5M48](/packages/desarrolla2-cache)[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)
