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

ActiveLibrary[Caching](/categories/caching)

waffle-commons/cache
====================

Cache component for Waffle framework.

0.1.0-beta5(2w ago)1321MITPHPPHP ^8.5CI passing

Since May 16Pushed 2w agoCompare

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

READMEChangelog (7)Dependencies (23)Versions (11)Used By (1)

[![Discord](https://camo.githubusercontent.com/b30f41baece56d71f7f496f7e39fd33a2a096221c66c648b350dd4fe14276c2e/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f3735353238383030313539323033333339313f6c6f676f3d646973636f7264)](https://discord.gg/eKgywnfXr2)[![PHP Version Require](https://camo.githubusercontent.com/3499e35b5689854ac585162850ce2094960915b40e8c1668a94784885ad7e11d/687474703a2f2f706f7365722e707567782e6f72672f776166666c652d636f6d6d6f6e732f63616368652f726571756972652f706870)](https://packagist.org/packages/waffle-commons/cache)[![PHP CI](https://github.com/waffle-commons/cache/actions/workflows/main.yml/badge.svg)](https://github.com/waffle-commons/cache/actions/workflows/main.yml)[![codecov](https://camo.githubusercontent.com/589fbc57eaf5f6d0e016f4b03593c1a6cef22796b8e210cb7ef56aeafb41eb31/68747470733a2f2f636f6465636f762e696f2f67682f776166666c652d636f6d6d6f6e732f63616368652f67726170682f62616467652e7376673f746f6b656e3d64373461633632612d373837322d343033352d386238622d626363336166313939316530)](https://codecov.io/gh/waffle-commons/cache)[![Latest Stable Version](https://camo.githubusercontent.com/6b016133acfdefba5a8e1960bb7f2f01f3a4081839c254362230ee62fae5d731/687474703a2f2f706f7365722e707567782e6f72672f776166666c652d636f6d6d6f6e732f63616368652f76)](https://packagist.org/packages/waffle-commons/cache)[![Latest Unstable Version](https://camo.githubusercontent.com/218e8c4101d54a1ebf58792d86446628b5df08d68b8ae357af89ddeb619ece6e/687474703a2f2f706f7365722e707567782e6f72672f776166666c652d636f6d6d6f6e732f63616368652f762f756e737461626c65)](https://packagist.org/packages/waffle-commons/cache)[![Total Downloads](https://camo.githubusercontent.com/4b1ac8c1567daa3f55955358f00cc69479b3230060858ba0111bc5821b000556/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776166666c652d636f6d6d6f6e732f63616368652e737667)](https://packagist.org/packages/waffle-commons/cache)[![Packagist License](https://camo.githubusercontent.com/d74cc6e641f9fe4ba7c6455384d12d3cf86df67072285c098dc900d5e70fb9ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776166666c652d636f6d6d6f6e732f6361636865)](https://github.com/waffle-commons/cache/blob/main/LICENSE.md)

Waffle Cache Component
======================

[](#waffle-cache-component)

> **Release:** `0.1.0-beta5` | [`CHANGELOG.md`](./CHANGELOG.md)**PSR Compliance:** PSR-6 (`Psr\Cache`) + PSR-16 (`Psr\SimpleCache`)

PSR-6 and PSR-16 compliant cache implementation for the Waffle Framework. Designed for FrankenPHP resident worker mode — every adapter is stateless across requests, fail-secure, and zero-baseline under Mago static analysis.

📦 Installation
--------------

[](#-installation)

```
composer require waffle-commons/cache
```

🧱 Adapters
----------

[](#-adapters)

AdapterUse caseWorker scope`ArrayCache`In-memory, ultra-fast. Lifetime = worker request cycle.Single worker`FileCache`Persistent filesystem cache with strict permission handling (no `/tmp` foot-guns).Per host`RedisCache`Distributed cache across multiple FrankenPHP workers via the Predis client.Cluster-wideAll adapters implement both `Psr\SimpleCache\CacheInterface` (PSR-16) and route through the same `KeyValidator`. `CachePool` provides the PSR-6 `CacheItemPoolInterface` view on top of any adapter.

🛡️ Hardening features
---------------------

[](#️-hardening-features)

- **JSON-only payloads (Beta 1):** `FileCache` and `RedisCache` serialize entries with `json_encode` / `json_decode` — **never** PHP `unserialize`. This eliminates the PHP Object Injection → RCE vector (OWASP A08) that native deserialization exposes in a long-lived worker process. JSON parse failures fail-secure (treated as a cache miss). Trade-off: only JSON-encodable values round-trip — objects come back as `stdClass`/arrays.
- **Stampede protection (`StampedeAwareTrait`):** probabilistic early expiration to prevent thundering-herd misses under high load.
- **Strict key validation (`KeyValidator`):** enforces the PSR-16 key character set; rejects invalid keys with `InvalidCacheKeyException`.
- **Stateless adapters:** no per-process mutable state — safe for FrankenPHP worker reuse.
- **Fail-secure exceptions:** `CacheException`, `CacheBackendUnavailableException`, `InvalidCacheKeyException` — all rooted in the `waffle-commons/contracts` exception hierarchy.

🐘 PHP 8.5 features used
-----------------------

[](#-php-85-features-used)

- **Typed constants** for adapter defaults.
- **Asymmetric visibility** (`public private(set)`) on adapter configuration.
- **Property hooks** for validating constructor inputs at the source.
- **`readonly` classes** for value objects (`CacheItem`).

🚀 Quick start
-------------

[](#-quick-start)

```
use Waffle\Commons\Cache\Adapter\ArrayCache;
use Waffle\Commons\Cache\Pool\CachePool;

$psr16 = new ArrayCache();
$psr16->set('user:42', ['name' => 'Ada'], ttl: 60);

$psr6 = new CachePool($psr16);
$item = $psr6->getItem('user:42');
```

Factory-based wiring (preferred in framework code) is provided by `CacheFactory`.

🧭 Architectural boundary (`mago guard`)
---------------------------------------

[](#-architectural-boundary-mago-guard)

An active dependency **perimeter** is enforced on every CI run by `vendor/bin/mago guard` (bundled into `composer mago`; zero baselines). The rules live in [`mago.toml`](./mago.toml) under `[guard.perimeter]` — a forbidden `use` statement fails the build, not a reviewer.

Production code under `Waffle\Commons\Cache` may depend **only** on:

- `Waffle\Commons\Cache\**` — itself
- `Waffle\Commons\Contracts\**` — the shared contracts package, the **only** Waffle dependency permitted
- `Predis\**` — the Predis client behind the `RedisCache` adapter
- `Psr\**` — PSR interfaces (PSR-6 / PSR-16)
- `@global` + `Psl\**` — PHP core and the PHP Standard Library

Test code under `WaffleTests\Commons\Cache` is unrestricted (`@all`). Structural rules are guarded too: interfaces must be named `*Interface`, `Exception\**` classes must end in `*Exception`, and any `Enum\**` namespace may hold only `enum` declarations.

Contract-first, component-agnostic by construction: components compose through `waffle-commons/contracts`, never directly through one another.

🧪 Testing
---------

[](#-testing)

```
docker exec -w /waffle-commons/cache waffle-dev composer tests
```

PHPUnit 11+ suite targets `>= 95%` line coverage.

🤝 Contributing
--------------

[](#-contributing)

See [CONTRIBUTING.md](./CONTRIBUTING.md). All contributions must respect the Mago Purge Protocol (zero baselines) and the FrankenPHP statelessness contract.

📄 License
---------

[](#-license)

MIT — see [LICENSE.md](./LICENSE.md).

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance97

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

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

Total

7

Last Release

16d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/34a7557a3fb23aaf788ca3892b9b7efdf96e753264bafd0599153c9e8a921316?d=identicon)[LesliePetrimaux](/maintainers/LesliePetrimaux)

---

Top Contributors

[![supa-chayajin](https://avatars.githubusercontent.com/u/695448?v=4)](https://github.com/supa-chayajin "supa-chayajin (41 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[millipress/millicache

WordPress Full-Page Cache based on Rules &amp; Flags. Delivers flexible, scalable caching workflows backed by Redis and ValKey in-memory stores.

722.9k2](/packages/millipress-millicache)[lion/bundle

Lion-framework configuration and initialization package

122.4k4](/packages/lion-bundle)

PHPackages © 2026

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