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

ActiveLibrary

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

A PSR-16 wrapper for WP transients.

0.2.x-dev(2y ago)139.2k↓100%4[1 issues](https://github.com/wp-oop/transient-cache/issues)[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 today

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 74% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity52

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

934d 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

[laravel/framework

The Laravel Framework.

34.6k500.1M14.9k](/packages/laravel-framework)[phpoffice/phpspreadsheet

PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine

13.9k286.2M1.1k](/packages/phpoffice-phpspreadsheet)[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.6k140.5M610](/packages/maatwebsite-excel)[mobiledetect/mobiledetectlib

Mobile\_Detect is a lightweight PHP class for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.

10.7k155.8M380](/packages/mobiledetect-mobiledetectlib)[illuminate/contracts

The Illuminate Contracts package.

703120.6M8.3k](/packages/illuminate-contracts)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69332.3M98](/packages/algolia-algoliasearch-client-php)

PHPackages © 2026

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