PHPackages                             snicco/better-wp-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. snicco/better-wp-cache

ActiveLibrary[Caching](/categories/caching)

snicco/better-wp-cache
======================

v1.10.1(1y ago)017.5k↓100%3LGPL-3.0-onlyPHPPHP ^7.4|^8.0

Since Apr 17Pushed 1y ago1 watchersCompare

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

READMEChangelogDependencies (10)Versions (35)Used By (3)

BetterWPCache - A PSR-16/PSR-6 cache implementation using the WordPress object cache
====================================================================================

[](#betterwpcache---a-psr-16psr-6-cache-implementation-using-the-wordpress-object-cache)

[![codecov](https://camo.githubusercontent.com/a99e6ec528fffd1664e95534f9a09a4a09d2afe62799ff0d8774dc22d8453f6c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f7665726167652d3130302532352d73756363657373)](https://codecov.io/gh/snicco/snicco)[![Psalm Type-Coverage](https://camo.githubusercontent.com/c12cfed65c7da16501f7a84e7861b8c4757fc30e9dc00bb2983783dbb3f3f84c/68747470733a2f2f73686570686572642e6465762f6769746875622f736e6963636f2f736e6963636f2f636f7665726167652e7376673f)](https://shepherd.dev/github/snicco/snicco)[![Psalm level](https://camo.githubusercontent.com/c5e90ffcf3a5aa1f78f93bddde5db7627b114329393aa87697df8cedc7f5391a/68747470733a2f2f73686570686572642e6465762f6769746875622f736e6963636f2f736e6963636f2f6c6576656c2e7376673f)](https://psalm.dev/)[![PhpMetrics - Static Analysis](https://camo.githubusercontent.com/364ffb28ea219affd0fed2e99cc046bac0bf41da3f1d3814e0cbe4a4bb54c994/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5068704d6574726963732d5374617469635f416e616c797369732d326561343466)](https://snicco.github.io/snicco/phpmetrics/BetterWPCache/index.html)[![PHP-Versions](https://camo.githubusercontent.com/241a10d25aa09d5e8a82ebd2b55780a63dd43736d958d4004c3166e650874aca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545372e34253743253545382e30253743253545382e312d626c7565)](https://camo.githubusercontent.com/241a10d25aa09d5e8a82ebd2b55780a63dd43736d958d4004c3166e650874aca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545372e34253743253545382e30253743253545382e312d626c7565)

**BetterWPCache** is a tiny library that allows you to use the [persistent WordPress object cache](https://developer.wordpress.org/reference/classes/wp_object_cache/)as a **PSR-16** cache or a **PSR-6** cache.

Additionally, **BetterWPCache** supports **cache tagging**.

This library is 100% integration tested against the official [php-cache/integration-tests](https://github.com/php-cache/integration-tests) using the [Redis Object Cache](https://github.com/rhubarbgroup/redis-cache) plugin by [Till Krüss](https://github.com/tillkruss).

Table of contents
-----------------

[](#table-of-contents)

1. [Motivation](#motivation)
2. [Installation](#installation)
3. [Usage](#usage)
    1. Does this work with any caching plugin?
    2. [PSR-6](#creating-a-psr-16-cache)
    3. [PSR-16](#creating-a-psr-6-cache)
    4. [Cache Tagging](#cache-tagging)
4. [Contributing](#contributing)
5. [Issues and PR's](#reporting-issues-and-sending-pull-requests)
6. [Security](#security)

Motivation
----------

[](#motivation)

We developed this library because many **WordPress** related components of the [**Snicco** project](https://github.com/snicco/snicco) require some form of caching.

To offer the greatest flexibility for users, they all only depend on the [PSR cache interfaces](https://www.php-fig.org/psr/psr-6/).

But using these interfaces' meant that there was no way of using these components inside **WordPress**with the already connected `WP_Object_Cache`.

**BetterWPCache** solves this need.

This library has three main use cases:

1. You are developing a **distributed WordPress library** and don't want to depend on the `WP_Object_Cache`.
2. You are using any PHP package that depends on the **PSR** cache interface, and you want to use your **WordPress**caching plugin for it.
3. You want **cache-tagging**, which is something that the `WP_Object_Cache` does not support.

Ideally, **WordPress** core would replace the custom `WP_Object_Cache` with the **PSR** cache interface instead, so that the need for this library vanishes. In the meantime **BetterWPCache** will do the job.

Installation
------------

[](#installation)

```
composer require snicco/better-wp-cache
```

Usage
-----

[](#usage)

### Does this work with any caching plugin?

[](#does-this-work-with-any-caching-plugin)

Short answer: **Yes!**

Long answer: As long as your caching plugin correctly implements the `wp_cache_xxx` functions. This library only uses the [official **WordPress** cache functions](https://github.com/WordPress/wordpress-develop/blob/5.9/src/wp-includes/cache.php).

---

### Creating a PSR-6 cache

[](#creating-a-psr-6-cache)

This is how you create a **PSR-6** cache from your favorite **WordPress** cache plugin.

```
use Snicco\Component\BetterWPCache\CacheFactory;

$cache_group = 'my_plugin';
$psr_6_cache = CacheFactory::psr6($cache_group);
```

---

### Creating a PSR-16 cache

[](#creating-a-psr-16-cache)

This is how you create a **PSR-16** cache from your favorite **WordPress** cache plugin.

```
use Snicco\Component\BetterWPCache\CacheFactory;

$cache_group = 'my_plugin';
$psr_16_cache = CacheFactory::psr16($cache_group);
```

---

### Cache tagging

[](#cache-tagging)

For cache tagging a **PSR-6** cache is needed.

```
use Snicco\Component\BetterWPCache\CacheFactory;

$cache_group = 'my_plugin';
$psr_6_cache = CacheFactory::psr6($cache_group);

$taggable_cache = CacheFactory::taggable($psr_6_cache);
```

`$taggable_cache` is an instance of [TaggableCacheItemPoolInterface](http://www.php-cache.com/en/latest/#tagging) which is in the process of becoming a **PSR** standard.

Taken from the [official documentation](http://www.php-cache.com/en/latest/#tagging):

```
use Snicco\Component\BetterWPCache\CacheFactory;

$cache = CacheFactory::taggable(CacheFactory::psr6('my_plugin'));

$item = $cache->getItem('tobias');
$item->set('value')->setTags(['tag0', 'tag1'])
$cache->save($item);

$item = $cache->getItem('aaron');
$item->set('value')->setTags(['tag0']);
$cache->save($item);

// Remove everything tagged with 'tag1'
$cache->invalidateTags(['tag1']);
$cache->getItem('tobias')->isHit(); // false
$cache->getItem('aaron')->isHit(); // true

$item = $cache->getItem('aaron');
echo $item->getPreviousTags(); // array('tag0')

// No tags will be saved again. This is the same as saving
// an item with no tags.
$cache->save($item);
```

Contributing
------------

[](#contributing)

This repository is a read-only split of the development repo of the [**Snicco** project](https://github.com/snicco/snicco).

[This is how you can contribute](https://github.com/snicco/snicco/blob/master/CONTRIBUTING.md).

Reporting issues and sending pull requests
------------------------------------------

[](#reporting-issues-and-sending-pull-requests)

Please report issues in the [**Snicco** monorepo](https://github.com/snicco/snicco/blob/master/CONTRIBUTING.md##using-the-issue-tracker).

Security
--------

[](#security)

If you discover a security vulnerability within **BetterWPCache**, please follow our [disclosure procedure](https://github.com/snicco/snicco/blob/master/SECURITY.md).

###  Health Score

37

—

LowBetter than 82% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

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

Recently: every ~1 days

Total

33

Last Release

609d ago

Major Versions

v1.10.0 → v2.0.0-beta.12024-09-01

v1.10.1 → v2.0.0-beta.72024-09-04

### Community

Maintainers

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

---

Top Contributors

[![snicco-bot](https://avatars.githubusercontent.com/u/101470239?v=4)](https://github.com/snicco-bot "snicco-bot (25 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/snicco-better-wp-cache/health.svg)

```
[![Health](https://phpackages.com/badges/snicco-better-wp-cache/health.svg)](https://phpackages.com/packages/snicco-better-wp-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.4M37](/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.8M81](/packages/cache-filesystem-adapter)[cache/array-adapter

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

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

PHPackages © 2026

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