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

ActiveLibrary

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

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

2.0.4(3y ago)1683↓100%[1 PRs](https://github.com/Pink-Crab/WP_PSR16_Cache/pulls)MITPHPPHP &gt;=7.1.0

Since Jan 26Pushed 2y 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 today

READMEChangelog (5)Dependencies (13)Versions (9)Used By (0)

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

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

Provides both WP Transient and WP FileSystem (Direct) implementation to [*PSR16`s CacheInterface*](https://github.com/php-fig/simple-cache).

[![alt text](https://camo.githubusercontent.com/b0e5516b487691bd19f571d33515d27863359e80138bec5350d3898722d6a4f3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f43757272656e745f56657273696f6e2d322e302e342d79656c6c6f772e7376673f7374796c653d666c6174 " ")](https://camo.githubusercontent.com/b0e5516b487691bd19f571d33515d27863359e80138bec5350d3898722d6a4f3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f43757272656e745f56657273696f6e2d322e302e342d79656c6c6f772e7376673f7374796c653d666c6174)![Open Source Love](https://camo.githubusercontent.com/2d4eac62d5f5830a5309100b88e0ecccb171aee1fbcd794149f4a580b0010c56/68747470733a2f2f6261646765732e66726170736f66742e636f6d2f6f732f6d69742f6d69742e7376673f763d313032)[![](https://github.com/Pink-Crab/WP_PSR16_Cache/workflows/GitHub_CI/badge.svg " ")](https://github.com/Pink-Crab/WP_PSR16_Cache/workflows/GitHub_CI/badge.svg)[![codecov](https://camo.githubusercontent.com/865f1b8cda0e16ab9f493164610eb768a3e7091c9f83e5a4f546c73f72ec9847/68747470733a2f2f636f6465636f762e696f2f67682f50696e6b2d437261622f57505f50535231365f43616368652f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d445a4f435a56504b424e)](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 with PHP7.1, 7.2, 7.3, 7.4, 8.0, 8.1
- Tested with WP5.5, 5.6, 5.7, 5.8, 5.9

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

[](#installation)

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

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

[](#getting-started)

Once you have the package installed and your autoloader has been included.

### File Cache

[](#file-cache)

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

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

// TRANSIENT CACHE
// Created with optional groups, adding a prefix to transient keys and set file extension.
$cache = new Transient_Cache('group_prefix' );

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

// Gets the value, if not set or expired returns null
$cache->get( 'cache_key', 'fallback' );

// Returns if valid cache item exists.
$cache->has( 'cache_key' );

// Deletes a cache if it exists.
$cahe->delete( 'cache_key' );

// Set multiple values, with a single expiry
$cache->setMultiple( ['key1' => 'Value1', 'key2' => 42], 1 * HOURS_IN_SECONDS );

// Get multiple values in a key => value array, with a shared default.
$cache->getMultiple( ['key1', 'key2'], 'FALLBACK' );

// Clears multiple keys.
$cache->deleteMultiple( ['key1', 'key2'] );

// Clear all cache items
$cache->clear();
```

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

[](#file_cache)

> Will create the defined base directory when the object is created.

The constructor takes 2 properties the path and the file extension. By default the file extension is **.do**.

```
$wp_uploads = wp_upload_dir();

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

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

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

If you plan on using this as a plugin and want to clean up after an install. You can just create an instance of the Class on activation and then run clear on uninstall

```
/**
 * Creates the cache directory
 */
function called_on_activation(){
    new File_Cache($wp_uploads['basedir'] . '/my-cache', '.cache');
}
/**
 * Clears all values form the cache directory.
 * Please note doesn't delete the folder.
 */
function called_on_uninstall(){
    (new File_Cache($wp_uploads['basedir'] . '/my-cache', '.cache'))->clear();
}
```

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

[](#transient-cache)

> Makes use of prefixed/grouped transient values. Preventing collisions while still allowing short and clean keys.

The constructor takes a single argument, this denotes the group that your transients will be created using. This can be omitted if you wanted no prefix on your keys.

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

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

// Will create a transient which can be recalled using either;
$value = get_transient('my_cache_my_key');
(new Transient_Cache('my_cache'))->get('my_key');

// You can create an instance with no key
$cache = New Transient_Cache();
$cache->set('my_other_key', ['some', 'data']);
// Get
$value = get_transient('my_other_key');
```

> PLEASE NOTE: Calling clear() will use $wpdb to get all transients from the database and clear any which start with your prefix. If you have no prefix defined, this could clear all of your transients and create some unusual side effected.

> ALSO: Some managed hosts store transients outside of the regular Options table. This can lead to problems when fetching all transients with your prefix.

---

Changelog
---------

[](#changelog)

- 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

27

↑

LowBetter than 51% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

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

Total

5

Last Release

1454d ago

### 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 (67 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

[laravel/framework

The Laravel Framework.

34.6k500.1M15.2k](/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.7k140.5M629](/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.8M386](/packages/mobiledetect-mobiledetectlib)[illuminate/contracts

The Illuminate Contracts package.

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

API powering the features of Algolia.

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

PHPackages © 2026

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