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

ActiveLibrary[Caching](/categories/caching)

mbretter/stk-cache
==================

Cache implementation PSR-6 and PSR-16

3.1.0(3y ago)13.0kBSD-3-ClausePHPPHP ^8.0CI failing

Since Sep 17Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mbretter/stk-cache)[ Packagist](https://packagist.org/packages/mbretter/stk-cache)[ Docs](https://www.bretterklieber.com)[ RSS](/packages/mbretter-stk-cache/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (9)Dependencies (7)Versions (10)Used By (0)

php cache implementation (PSR-6 and PSR-16)
===========================================

[](#php-cache-implementation-psr-6-and-psr-16)

[![License](https://camo.githubusercontent.com/2b599ab1ace97388d4375b87919f92781a1a61d016fe640a5c4d15fc365deed1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4253442d626c75652e737667)](https://opensource.org/licenses/BSD-3-Clause)[![PHP 8.0](https://camo.githubusercontent.com/10998de7b5b19371ab32c326a0d9d29f0b1aa976896a3525fb7d96b6c8e523c4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e302d79656c6c6f772e737667)](http://www.php.net)[![Latest Stable Version](https://camo.githubusercontent.com/b3b659f9c2cd350fe1bcdd83bd851537cec1bec8de3ce2da33839144bdb35e35/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d627265747465722f73746b2d63616368652e737667)](https://packagist.org/packages/mbretter/stk-cache)[![Total Downloads](https://camo.githubusercontent.com/fe7f579348399825dfd200c99ccc8075c277a93152bb8489393fcd18eb8ef01c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d627265747465722f73746b2d63616368652e737667)](https://packagist.org/packages/mbretter/stk-cache)[![CI](https://github.com/mbretter/stk-cache/actions/workflows/ci.yml/badge.svg)](https://github.com/mbretter/stk-cache/actions/workflows/ci.yml/badge.svg)

Support for memcached and APCu is included.

Memcached
---------

[](#memcached)

```
$memcached = new Memcached();
$memcached->addServer("127.0.0.1", 11211, 50]);
$pool = new Cache\Pool\Memcached($memcached);

$cache = new Cache\Cache($pool);
```

APCu
----

[](#apcu)

```
$pool = new Cache\Pool\APCu();
$cache = new Cache\Cache($pool);
```

Blackhole
---------

[](#blackhole)

The blackhole pool is a dummy pool, which does not do any caching. It can be used on a development environment, when caching should be disabled.

```
$pool = new Cache\Pool\Blackhole();
$cache = new Cache\Cache($pool);
```

Memory
------

[](#memory)

A cache pool which uses an instance variable of the pool object as cache.

```
$pool = new Cache\Pool\Memory();
$cache = new Cache\Cache($pool);
```

Additional methods
------------------

[](#additional-methods)

Besides, the PSR standards, the Cache has implemented some useful extra methods.

### getSet

[](#getset)

getSet invokes a closure, if the key was not found inside the cache. This helps to build a linear code base, without additional conditions checking whether the key was found or not.

If the key was found, the value is returned directly, without invkoing the closure.

```
$pool = new Cache\Pool\APCu();
$cache = new Cache\Cache($pool);

$val = $cache->getSet('mykey', function() {
    // ... do some expensive calculations
    return $val;
});
```

### Grouping

[](#grouping)

If you want to invalidate a group of cache items, by only removing one key, this could be done by using the group feature.

```
$groupkey = 'mygroup';

$cache->setGrouped($groupkey, 'key1', $val1);
$cache->setGrouped($groupkey, 'key2', $val2);
$cache->setGrouped($groupkey, 'key-' . uniqid(), $val2);

$cache->delete($groupkey); // invalidates key1, key2, key-xxxx

$val = $cache->getGrouped($groupkey, 'key1'); // $val is null
```

getSetGrouped works in the same way as getSet, but with the additional group key.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity69

Established project with proven stability

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

Recently: every ~155 days

Total

9

Last Release

1375d ago

Major Versions

1.0.3 → 2.0.02020-11-27

2.1.0 → 3.0.02021-12-15

PHP version history (4 changes)1.0.0PHP ^7.2

2.0.0PHP ^7.4

2.1.0PHP ^7.4|^8.0

3.0.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1787808?v=4)[Michael Bretterklieber](/maintainers/mbretter)[@mbretter](https://github.com/mbretter)

---

Top Contributors

[![mbretter](https://avatars.githubusercontent.com/u/1787808?v=4)](https://github.com/mbretter "mbretter (18 commits)")

---

Tags

cachememcachedphppsr-16psr-6

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k348.9M2.5k](/packages/symfony-cache)[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.4M38](/packages/cache-adapter-common)[cache/cache

Library of all the php-cache adapters

2712.7M22](/packages/cache-cache)[cache/filesystem-adapter

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

705.8M82](/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)
