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

ActiveLibrary[Caching](/categories/caching)

doekenorg/cache-middleware
==========================

An experimental middleware decorator for a PSR-6 cache pool

v0.1.0(3y ago)53MITPHP

Since May 21Pushed 3y ago1 watchersCompare

[ Source](https://github.com/doekenorg/cache-middleware)[ Packagist](https://packagist.org/packages/doekenorg/cache-middleware)[ RSS](/packages/doekenorg-cache-middleware/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

PSR-6 Cache Middleware
======================

[](#psr-6-cache-middleware)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5a147782a93cc981996e4822efa6be4d6dbdabcf17012389c433df3ba8784c11/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646f656b656e6f72672f63616368652d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/doekenorg/cache-middleware)

This is an experimental package that provides middleware for any [PSR-6 cache pool](https://www.php-fig.org/psr/psr-6/).

Usage
-----

[](#usage)

To apply middlewares you decorate your PSR-6 cache pool with the `DoekeNorg\CacheMiddleware\MiddlewareDecorator`. The constructor of the decorator receives the decorated cache pool, as well as an optional list of middleware classes. You can also add more middlewares by calling the `addMiddleware(...$middlewares)` method on the decorator.

```
use DoekeNorg\CacheMiddleware\MiddlewareCachePool;

$regular_psr6_cache_pool = ...; // your current PSR-6 cache pool
$decorator_cache_pool = new MiddlewareCachePool($regular_psr6_cache_pool, ...$middlewares);
//or
$decorator_cache_pool = new MiddlewareCachePool($regular_psr6_cache_pool);
$decorator_cache_pool->addMiddleware(...$middlewares);
```

Types of middleware
-------------------

[](#types-of-middleware)

This package provides three middleware interfaces:

- `MiddlewareGetInterface`: This middleware is called in combination with `->getItem()` and `->getItems()`
- `MiddlewareSaveInterface`: This middleware is called in combination with `->save()` and `->safeDefered()`
- `MiddlewareDeleteInterface`: This middleware is called in combination with `->deleteItem()` and `->deleteItems()`

Implementing the interfaces
---------------------------

[](#implementing-the-interfaces)

Every interface has a single `process` method that gets called in the middleware process. So a single middleware class can implement multiple middleware interfaces, and provide a common goal.

```
use DoekeNorg\CacheMiddleware\MiddlewareGetInterface;
use DoekeNorg\CacheMiddleware\MiddlewareSaveInterface;
use DoekeNorg\CacheMiddleware\MiddlewareDeleteInterface;
use Psr\Cache\CacheItemInterface;

final class ExampleMiddleware implements MiddlewareGetInterface, MiddlewareSaveInterface, MiddlewareDeleteInterface {
    public function processGet(string $key, callable $next): CacheItemInterface {
        $cache_item = $next($key);
        // do something to the cache item
        return $cache_item;
    }

    public function processSave(CacheItemInterface $cacheItem, callable $next): bool {
        // do something to the cache item
        return $next($cacheItem);
    }

    public function processDelete(string $key, callable $next): bool {
        // perform some action based on the key or the deleted result.
        return $next($key);
    }
}
```

Notes
-----

[](#notes)

This package is a fun experiment to see if the middleware pattern can be useful around a PSR-6 cache. The package is under development, and the implementation can change during the non-stable phase. As long as this is a `0.*.*` release consider every *minor* change as a *major* update.

**Warning:** While it is possible to change the cache keys of the methods I do not recommend this in the middleware. Use it to update the cache item (adding tags, deleting other items for a given key, etc.).

**Caveat:** To trigger the middlewares on all items in combination with `getItems()` and `deleteItems()` these functions do *NOT* call these functions on the decorated cache pool, but rather call `getItem()` and `deleteItem()` multiple times on the decorator. This technically makes this decorator a proxy, but practically it still is a decorator. Just note that if you need the inner methods called, this package probably isn't for you, and you should use a custom decorator.

Changelog
---------

[](#changelog)

Please see the [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

1449d ago

### Community

Maintainers

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

---

Top Contributors

[![doekenorg](https://avatars.githubusercontent.com/u/529515?v=4)](https://github.com/doekenorg "doekenorg (9 commits)")

---

Tags

middlewarepsr-6cache poolcache item

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[laminas/laminas-cache

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

1076.9M130](/packages/laminas-laminas-cache)[cache/adapter-common

Common classes for PSR-6 adapters

11124.4M37](/packages/cache-adapter-common)[cache/hierarchical-cache

A helper trait and interface to your PSR-6 cache to support hierarchical keys.

6016.1M10](/packages/cache-hierarchical-cache)[cache/filesystem-adapter

A PSR-6 cache implementation using filesystem. This implementation supports tags

705.8M81](/packages/cache-filesystem-adapter)[cache/array-adapter

A PSR-6 cache implementation using a php array. This implementation supports tags

548.3M151](/packages/cache-array-adapter)

PHPackages © 2026

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