PHPackages                             pinkcrab/wp-psr16-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. pinkcrab/wp-psr16-cache

ActiveLibrary[Caching](/categories/caching)

pinkcrab/wp-psr16-cache
=======================

A WordPress based implementation of the PSR16 Cacheinterface using transient or the WP\_File\_System

2.1.0(2mo ago)1694[4 PRs](https://github.com/Pink-Crab/WP_PSR16_Cache/pulls)1MITPHPPHP &gt;=8.0.0CI passing

Since Jan 26Pushed 1mo agoCompare

[ Source](https://github.com/Pink-Crab/WP_PSR16_Cache)[ Packagist](https://packagist.org/packages/pinkcrab/wp-psr16-cache)[ Docs](https://pinkcrab.co.uk)[ RSS](/packages/pinkcrab-wp-psr16-cache/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (6)Dependencies (26)Versions (15)Used By (1)

WP PSR16 Simple Cache
=====================

[](#wp-psr16-simple-cache)

A WordPress-backed PSR-16 `CacheInterface` implementation with two interchangeable drivers: WP transients and the WP `Direct` filesystem. See [PSR-16 SimpleCache](https://github.com/php-fig/simple-cache) for the contract these drivers implement.

[![Latest Stable Version](https://camo.githubusercontent.com/8a3da3a6690f0db906d7d0284f2d43bce9066db1a9c3429c19b58b7e62310bee/68747470733a2f2f706f7365722e707567782e6f72672f70696e6b637261622f77702d70737231362d63616368652f76)](https://packagist.org/packages/pinkcrab/wp-psr16-cache) [![Total Downloads](https://camo.githubusercontent.com/61b56b1f7215b11b3392a46fd6b79816d7877b5e9d7c2d97c872d5667193d2c3/68747470733a2f2f706f7365722e707567782e6f72672f70696e6b637261622f77702d70737231362d63616368652f646f776e6c6f616473)](https://packagist.org/packages/pinkcrab/wp-psr16-cache) [![Latest Unstable Version](https://camo.githubusercontent.com/386996f1e2946b07db73f9346172a39072c466e2621abb1ccb813460e08ef269/68747470733a2f2f706f7365722e707567782e6f72672f70696e6b637261622f77702d70737231362d63616368652f762f756e737461626c65)](https://packagist.org/packages/pinkcrab/wp-psr16-cache) [![License](https://camo.githubusercontent.com/8e99bb7950630ab6cc3d37d5244de413bb4ea3fe80e93973a92df2de04147407/68747470733a2f2f706f7365722e707567782e6f72672f70696e6b637261622f77702d70737231362d63616368652f6c6963656e7365)](https://packagist.org/packages/pinkcrab/wp-psr16-cache) [![PHP Version Require](https://camo.githubusercontent.com/8d820d27a6cc0cd6595b9c4edfe86402dff854aed7e1ad411fafd1df57f06a88/68747470733a2f2f706f7365722e707567782e6f72672f70696e6b637261622f77702d70737231362d63616368652f726571756972652f706870)](https://packagist.org/packages/pinkcrab/wp-psr16-cache)[![GitHub contributors](https://camo.githubusercontent.com/f77d4774334a01e6db7806006fe979b4a7faccb44b2f65de38ac04c3b47d7e75/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f50696e6b2d437261622f57505f50535231365f43616368653f6c6162656c3d436f6e7472696275746f7273)](https://camo.githubusercontent.com/f77d4774334a01e6db7806006fe979b4a7faccb44b2f65de38ac04c3b47d7e75/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f50696e6b2d437261622f57505f50535231365f43616368653f6c6162656c3d436f6e7472696275746f7273)[![GitHub issues](https://camo.githubusercontent.com/7ddfe15b83b4af13e53e734771913a24047a76925bd598c08f8ed8bfe2be9ba5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f50696e6b2d437261622f57505f50535231365f4361636865)](https://camo.githubusercontent.com/7ddfe15b83b4af13e53e734771913a24047a76925bd598c08f8ed8bfe2be9ba5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f50696e6b2d437261622f57505f50535231365f4361636865)[![WP 6.6 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/WP_PSR16_Cache/actions/workflows/WP_6_6.yaml/badge.svg)](https://github.com/Pink-Crab/WP_PSR16_Cache/actions/workflows/WP_6_6.yaml)[![WP 6.7 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/WP_PSR16_Cache/actions/workflows/WP_6_7.yaml/badge.svg)](https://github.com/Pink-Crab/WP_PSR16_Cache/actions/workflows/WP_6_7.yaml)[![WP 6.8 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/WP_PSR16_Cache/actions/workflows/WP_6_8.yaml/badge.svg)](https://github.com/Pink-Crab/WP_PSR16_Cache/actions/workflows/WP_6_8.yaml)[![WP 6.9 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/WP_PSR16_Cache/actions/workflows/WP_6_9.yaml/badge.svg)](https://github.com/Pink-Crab/WP_PSR16_Cache/actions/workflows/WP_6_9.yaml)[![codecov](https://camo.githubusercontent.com/36d5241a034bd8f37b93d7bbf499a2efa69e6accfb1dc6f48707e8abb5034ae1/68747470733a2f2f636f6465636f762e696f2f67682f50696e6b2d437261622f57505f50535231365f43616368652f67726170682f62616467652e7376673f746f6b656e3d445a4f435a56504b424e)](https://codecov.io/gh/Pink-Crab/WP_PSR16_Cache)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/8615cc89a10978b3e18060273a9ed1a2f0b7d8a8553e9ab6fbf00c65fdceca6e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f50696e6b2d437261622f57505f50535231365f43616368652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Pink-Crab/WP_PSR16_Cache/?branch=master)

---

Requirements
------------

[](#requirements)

Requires Composer and WordPress.

> **TESTED AGAINST**
>
> - PHP 8.0, 8.1, 8.2, 8.3 &amp; 8.4
> - WP 6.6, 6.7, 6.8 &amp; 6.9
> - MySQL 8.4

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

[](#installation)

```
$ composer require pinkcrab/wp-psr16-cache
```

Getting Started
---------------

[](#getting-started)

Once the package is installed and your autoloader has been included, the two drivers can be used interchangeably through PSR-16's `CacheInterface`.

```
use PinkCrab\WP_PSR16_Cache\File_Cache;
use PinkCrab\WP_PSR16_Cache\Transient_Cache;

// FILE CACHE
// Creates the directory at the path passed, if it doesn't exist.
$cache = new File_Cache( 'path/to/dir', '.do' );

// TRANSIENT CACHE
// Optional group adds a prefix to every transient key.
$cache = new Transient_Cache( 'group_prefix' );

// Set a single item.
$cache->set( 'cache_key', $data, 24 * HOURS_IN_SECONDS );

// Get the value; returns the fallback if the key is missing or expired.
$cache->get( 'cache_key', 'fallback' );

// True when a valid (non-expired) cache item exists.
$cache->has( 'cache_key' );

// Delete a single cache entry.
$cache->delete( 'cache_key' );

// Batch writes with a shared expiry.
$cache->setMultiple( array( 'key1' => 'Value1', 'key2' => 42 ), 1 * HOURS_IN_SECONDS );

// Batch reads with a shared default.
$cache->getMultiple( array( 'key1', 'key2' ), 'FALLBACK' );

// Batch delete.
$cache->deleteMultiple( array( 'key1', 'key2' ) );

// Clear every key tracked by this cache instance.
$cache->clear();
```

File\_Cache
-----------

[](#file_cache)

> Creates the configured base directory when the object is constructed.

The constructor takes two arguments — the path and the file extension. The extension defaults to **.do**.

```
$wp_uploads = wp_upload_dir();

$cache = new File_Cache( $wp_uploads['basedir'] . '/my-cache', '.cache' );

$cache->set( 'my_key', array( 'some', 'data' ) );

// Creates  /public/wp-content/uploads/my-cache/my_key.cache
```

A common pattern is to warm the directory on plugin activation and clear it on uninstall:

```
/**
 * Creates the cache directory.
 */
function called_on_activation() {
    new File_Cache( $wp_uploads['basedir'] . '/my-cache', '.cache' );
}

/**
 * Removes every cache entry in the directory.
 * Note: clear() removes the files inside the directory; the directory itself is left in place.
 */
function called_on_uninstall() {
    ( new File_Cache( $wp_uploads['basedir'] . '/my-cache', '.cache' ) )->clear();
}
```

Transient Cache
---------------

[](#transient-cache)

> Uses prefixed/grouped transient values — prevents collisions while still allowing short, clean keys.

The constructor takes a single optional argument: the group name that every transient written through this instance will be prefixed with. Omit it for no prefix.

```
$cache = new Transient_Cache( 'my_cache' );

$cache->set( 'my_key', array( 'some', 'data' ) );

// The value can be read back via either:
$value = get_transient( 'my_cache_my_key' );
( new Transient_Cache( 'my_cache' ) )->get( 'my_key' );

// Or create an instance with no group prefix:
$cache = new Transient_Cache();
$cache->set( 'my_other_key', array( 'some', 'data' ) );
$value = get_transient( 'my_other_key' );
```

> **PLEASE NOTE**`clear()` queries `$wpdb` for every transient whose key matches the configured prefix and deletes them. If no group prefix is set, this can match — and delete — unrelated transients in the same database. Always set a group on a cache you plan to clear.

> **ALSO**Some managed hosts store transients outside the regular `options` table. Where that happens, the prefix-scan in `clear()` won't see them and they will not be cleared.

---

Changelog
---------

[](#changelog)

- 2.1.0 - Drop PHP 7.x, require PHP 8.0+. Bump dev deps: phpstan 2.x, phpstan-wordpress 2.x, phpunit 9.x, WP 6.6-6.9 test matrix. Replace the `php.yaml` workflow with WP\_6\_6 / WP\_6\_7 / WP\_6\_8 / WP\_6\_9 actions (`mysql:8.4`). Add `.scrutinizer.yml`. Force `FS_METHOD=direct` in test config so `File_Cache` consistently gets `WP_Filesystem_Direct` under PHP 8.x. Expand `@param` / `@return` docblocks across the source tree. No public API changes.
- 2.0.4 - Updated dev dependencies and added scrutinizer to CI
- 2.0.3 - Fixed missing wp filesystem include
- 2.0.2 - Readme formatting, added in additional tests for 100% coverage.
- 2.0.1 - Fixed trailin comma issue in File\_Cache and setup all github CI workflows.
- 2.0.0 - Moved to composer and switched to using WP\_FileSystem over raw PHP functions.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance90

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity66

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

Recently: every ~476 days

Total

6

Last Release

67d ago

PHP version history (2 changes)2.0.0PHP &gt;=7.1.0

2.1.0PHP &gt;=8.0.0

### Community

Maintainers

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

---

Top Contributors

[![gin0115](https://avatars.githubusercontent.com/u/28779094?v=4)](https://github.com/gin0115 "gin0115 (70 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pinkcrab-wp-psr16-cache/health.svg)

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

###  Alternatives

[moonshine/moonshine

Laravel administration panel

1.3k239.9k75](/packages/moonshine-moonshine)[laminas/laminas-cache

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

1067.2M145](/packages/laminas-laminas-cache)[sabre/cache

Simple cache abstraction layer implementing PSR-16

551.3M4](/packages/sabre-cache)[voku/simple-cache

Simple Cache library

322.6M9](/packages/voku-simple-cache)[graham-campbell/bounded-cache

A Bounded TTL PSR-16 Cache Implementation

112.1M10](/packages/graham-campbell-bounded-cache)[neos/cache

Neos Cache Framework

102.1M36](/packages/neos-cache)

PHPackages © 2026

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