PHPackages                             felixarntz/wp-psr-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. felixarntz/wp-psr-cache

ActiveWordpress-muplugin

felixarntz/wp-psr-cache
=======================

Object cache implementation for WordPress that acts as an adapter for PSR-6 and PSR-16 caching libraries.

342154[2 issues](https://github.com/felixarntz/wp-psr-cache/issues)PHP

Since Apr 2Pushed 8y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

[![Build Status](https://camo.githubusercontent.com/e2d3ff2d083e263d6bb1d17e6348cdffae73aaea23a654b2e1011461afe1f7ac/68747470733a2f2f6170692e7472617669732d63692e6f72672f66656c697861726e747a2f77702d7073722d63616368652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/felixarntz/wp-psr-cache)[![All Contributors](https://camo.githubusercontent.com/f7e7ee5949a35d448797601f9193f3e6b8108dc258029dad8457e109c52b4a41/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f616c6c5f636f6e7472696275746f72732d342d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](#contributors)[![Code Climate](https://camo.githubusercontent.com/4bee943832a9a30800f271110f8dc9749b6f8fb260565ea046889a05d00daeaf/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f66656c697861726e747a2f77702d7073722d63616368652f6261646765732f6770612e737667)](https://codeclimate.com/github/felixarntz/wp-psr-cache)[![Test Coverage](https://camo.githubusercontent.com/81047d1e958e979a5b5f0f747b42e52235fc3649ee783eb73cf692df5d043eee/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f66656c697861726e747a2f77702d7073722d63616368652f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/felixarntz/wp-psr-cache/coverage)[![Latest Stable Version](https://camo.githubusercontent.com/f451b7f2e4a7f3a0e12b8d799f6c731a282b8d0c162eae498b330884d1587e4e/68747470733a2f2f706f7365722e707567782e6f72672f66656c697861726e747a2f77702d7073722d63616368652f76657273696f6e)](https://packagist.org/packages/felixarntz/wp-psr-cache)[![License](https://camo.githubusercontent.com/4ba6d8e4a6ea6b6b3917c5c49faf7bed9101083e638dc81c07639325ca6b6d94/68747470733a2f2f706f7365722e707567782e6f72672f66656c697861726e747a2f77702d7073722d63616368652f6c6963656e7365)](https://packagist.org/packages/felixarntz/wp-psr-cache)

WP PSR Cache
============

[](#wp-psr-cache)

Object cache implementation for WordPress that acts as an adapter for PSR-6 and PSR-16 caching libraries.

What do PSR-6 and PSR-16 mean?
------------------------------

[](#what-do-psr-6-and-psr-16-mean)

[PSR-6](http://www.php-fig.org/psr/psr-6/) and [PSR-16](http://www.php-fig.org/psr/psr-16/) are standards established by the [PHP-FIG](http://www.php-fig.org/) organization. These standards are commonly used in PHP projects of any kind (WordPress is unfortunately an exception), and since this library acts as an adapter, you can use any compatible caching library of your choice with WordPress now. Popular examples include the [Symfony Cache Component](https://github.com/symfony/cache) or [Stash](https://github.com/tedious/Stash).

Features
--------

[](#features)

- Any PSR-6 or PSR-16 cache implementation can be used
- Persistent and non-persistent cache implementations can be individually specified
- Support for reading/writing/deleting multiple cache keys at once
- Only checks persistent cache if value not already present in non-persistent cache
- Full multisite support, including site and network switching
- Allows registration of further cache implementations for fine-grained control per cache group

How to Install
--------------

[](#how-to-install)

Require this library as a dependency when managing your project with Composer (for example by using [Bedrock](https://github.com/roots/bedrock)). You also have to install an actual [PSR-6](https://packagist.org/providers/psr/cache-implementation) or [PSR-16](https://packagist.org/providers/psr/simple-cache-implementation) cache implementation.

After the installation, you need to move the `includes/object-cache.php` file into your `wp-content` directory. If you prefer, you can also automate that process by adding the following to your project's `composer.json`:

```
	"scripts": {
		"post-install-cmd": [
			"cp -rp web/app/mu-plugins/wp-psr-cache/includes/object-cache.php web/app/object-cache.php"
		]
	}

```

Then, replace the inline comment in the `object-cache.php` file with the actual instantiations of the classes you want to use. You need to provide two implementations, one for the persistent cache and another for the non-persistent cache.

To prevent conflicts with multiple WordPress installations accessing the same cache service, it is recommended to define a unique `WP_CACHE_KEY_PREFIX` constant in your `wp-config.php` file.

### Example

[](#example)

The following example uses the `symfony/cache` library, so you have to require it in your `composer.json`. It then uses that library's Memcached implementation as persistent cache and its array storage as non-persistent cache.

```
