PHPackages                             wp-oop/transient-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. wp-oop/transient-cache

ActiveLibrary[Caching](/categories/caching)

wp-oop/transient-cache
======================

A PSR-16 wrapper for WP transients.

0.2.x-dev(2y ago)139.2k↓100%4[1 PRs](https://github.com/wp-oop/transient-cache/pulls)GPL-2.0-or-laterPHPPHP ^7.4 | ^8.0

Since Mar 20Pushed 2y ago2 watchersCompare

[ Source](https://github.com/wp-oop/transient-cache)[ Packagist](https://packagist.org/packages/wp-oop/transient-cache)[ RSS](/packages/wp-oop-transient-cache/feed)WikiDiscussions 0.2.x Synced 1mo ago

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

WP Transient Cache
==================

[](#wp-transient-cache)

[![Build Status](https://camo.githubusercontent.com/ee18cee9704b7f888635c24cd0f31bc94dbc6cb509ec7f83915beec6308ced51/68747470733a2f2f7472617669732d63692e636f6d2f77702d6f6f702f7472616e7369656e742d63616368652e7376673f6272616e63683d646576656c6f70)](https://travis-ci.org/wp-oop/transient-cache)[![Latest Stable Version](https://camo.githubusercontent.com/d5064f11130785ade2b9012ff9ae064246284b9636b601b57ab90bf071a14a52/68747470733a2f2f706f7365722e707567782e6f72672f77702d6f6f702f7472616e7369656e742d63616368652f76657273696f6e)](https://packagist.org/packages/wp-oop/transient-cache)[![Latest Unstable Version](https://camo.githubusercontent.com/209b8404176b2bbd775c78ed749d7d7a81650c4f172882094ef084cfd76ed8be/68747470733a2f2f706f7365722e707567782e6f72672f77702d6f6f702f7472616e7369656e742d63616368652f762f756e737461626c65)](//packagist.org/packages/wp-oop/transient-cache)

A fully compliant [PSR-16](https://www.php-fig.org/psr/psr-16/) wrapper for WP transients.

Details
-------

[](#details)

A common means of caching values in WordPress is by using [transients](https://codex.wordpress.org/Transients_API). However, this approach suffers from several problems:

1. Coupling to WordPress. You can't just suddenly substitute the caching mechanism you are using for another mechanism, and everything still works.
2. No namespacing. All transients live in the same namespace, and independent consumers cannot reliably use arbitrary keys without the risk of possible conflict.
3. No true modularity. Due to the above, if your application is [modular](https://github.com/Dhii/module-interface), it cannot decide which caching mechanisms to use for what, because that would have already been decided by your modules.
4. Missing features. For example, it is not possible to clear all values related to a particular thing in one go. Exceptions are missing too, and you have to rely on ambiguous return values.

This standards-compliant wrapper addresses all of the above. It is a true PSR-16 cache, which uses WordPress transients as storage. Exceptions are raised, interfaces implemented, and true false-negative detection is in place. Each instance of the cache pool is logically independent from other instances, provided that it is given a unique name. The application is once again in control, and modules that use cache can become platform agnostic.

### Compatibility

[](#compatibility)

- `CachePool` and `CachePoolFactory` offer best-practices error handling, throwing meaningful exceptions when something goes wrong. This violates PSR-16, but allows you to know what is failing.
- `SilentPool` and `SilentPoolFactory` offer PSR-16 compatibility at the cost of error handling, hiding exceptions, and returning standards-compatible values. This complies with PSR-16, but at the cost of clarity and verbosity.

### Usage

[](#usage)

```
/*
 * Set up the factory - usually in a service definition
 */
use wpdb;
use Psr\SimpleCache\CacheInterface;
use WpOop\TransientCache\CachePoolFactory;
use WpOop\TransientCache\SilentPoolFactory;

/* @var $wpdb wpdb */
$factory = new CachePoolFactory($wpdb);
// Optionally hide exceptions for PSR-16 compatibility
$factory = new SilentPoolFactory($factory); // Optional, and not recommended for testing environments!

/*
 * Create cache pools - usually somewhere else
 */
// Same wpdb instance used, default value generated automatically
$pool1 = $factory->createCachePool('client-access-tokens');
$pool2 = $factory->createCachePool('remote-api-responses');
$pool3 = $factory->createCachePool('other-stuff');

/*
 * Use cache pools - usually injected into a client class
 */

// No collision of key between different pools
$pool1->set('123', $someToken);
$pool2->set('123', $someResponseBody);
$pool3->set('123', false);

// Depend on an interop standard
(function (CacheInterface $cache) {
    // False negative detection: correctly determines that the value is actually `false`
    $cache->has('123'); // true
    $cache->get('123', uniqid('default')) === false; // true
})($pool3);

// Clear all values within a pool
$pool2->clear();
$pool2->has('123'); // false
$pool1->has('123'); // true
```

### Limitations

[](#limitations)

#### Key Length

[](#key-length)

Due to the way the underlying backend (the WordPress transients via options) works, **the combined length of the pool name and cache key MUST NOT exceed a 171 char limit**. This is because (at least in WP 5.0+) the [length of the `option_name` field of the `options` table is 191 chars](https://github.com/WordPress/WordPress/blob/5.0-branch/wp-admin/includes/schema.php#L142), and transients require the longest prefix of `_transient_timeout_` to the option name, which together with the 1-char separator is 20 chars. Using anything greater than this length will result in potentially devastating behaviour described in [Trac #15058](https://core.trac.wordpress.org/ticket/15058).

In any case, the general recommendation is that **consumers SHOULD NOT use cache keys longer than 64 chars**, as this is the minimal length required for support by the PSR-16 spec. Using anything longer than that will cause consumers to become dependent on implementation detail, which breaks interoperability. Given that, **the cache pool name SHOULD NOT exceed 107 chars**.

#### Value Length

[](#value-length)

The storage backend (WP options) [declares](https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/schema.php#L144) the corresponding field to be of type [`LONGTEXT`](https://dev.mysql.com/doc/refman/8.0/en/blob.html), which [allows](https://dev.mysql.com/doc/refman/8.0/en/storage-requirements.html#data-types-storage-reqs-strings) up to **4 GB** (232) of data. This is therefore the limit on cache values.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 79.8% 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 ~205 days

Recently: every ~287 days

Total

7

Last Release

983d ago

PHP version history (2 changes)v0.1.0-alpha1PHP ^7.1

0.2.x-devPHP ^7.4 | ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1894e91b32c9f80d8f30a42d360af6983a507f1cf2c621b7c9a0a0de14e011c5?d=identicon)[XedinUnknown](/maintainers/XedinUnknown)

---

Top Contributors

[![XedinUnknown](https://avatars.githubusercontent.com/u/1428973?v=4)](https://github.com/XedinUnknown "XedinUnknown (67 commits)")[![mecha](https://avatars.githubusercontent.com/u/5425482?v=4)](https://github.com/mecha "mecha (11 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (5 commits)")[![BrianHenryIE](https://avatars.githubusercontent.com/u/4720401?v=4)](https://github.com/BrianHenryIE "BrianHenryIE (1 commits)")

---

Tags

cachecache-poolpsr-16transientstransients-apiwordpress-transientswp-transients

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/wp-oop-transient-cache/health.svg)

```
[![Health](https://phpackages.com/badges/wp-oop-transient-cache/health.svg)](https://phpackages.com/packages/wp-oop-transient-cache)
```

###  Alternatives

[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/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)[cache/redis-adapter

A PSR-6 cache implementation using Redis (PhpRedis). This implementation supports tags

523.9M27](/packages/cache-redis-adapter)[cache/simple-cache-bridge

A PSR-6 bridge to PSR-16. This will make any PSR-6 cache compatible with SimpleCache.

423.1M27](/packages/cache-simple-cache-bridge)

PHPackages © 2026

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