PHPackages                             valu/wp-graphql-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. valu/wp-graphql-cache

ActiveWordpress-plugin[Caching](/categories/caching)

valu/wp-graphql-cache
=====================

Flexible caching framework for WPGraphQL

v0.1.0(4y ago)4220.5k↓50%8[9 issues](https://github.com/valu-digital/wp-graphql-cache/issues)[1 PRs](https://github.com/valu-digital/wp-graphql-cache/pulls)GPL-2.0-or-laterPHP

Since May 11Pushed 4y ago2 watchersCompare

[ Source](https://github.com/valu-digital/wp-graphql-cache)[ Packagist](https://packagist.org/packages/valu/wp-graphql-cache)[ RSS](/packages/valu-wp-graphql-cache/feed)WikiDiscussions master Synced 1mo ago

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

WARNING: This is an ALPHA release and not feature complete yet.

WPGraphQL Cache
===============

[](#wpgraphql-cache)

Flexible caching framework for WPGraphQL v0.9.0 or later

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

[](#installation)

```
composer require valu/wp-graphql-cache

```

Or you can clone it from Github to your plugins using the stable branch

```
cd wp-content/plugins
git clone --branch stable https://github.com/valu-digital/wp-graphql-cache.git

```

Query Caching
-------------

[](#query-caching)

If you want to just start caching all your queries for a given period of time you can just add this to your theme's `functions.php` or to a mu-plugin:

```
use WPGraphQL\Extensions\Cache\CacheManager;

CacheManager::register_graphql_query_cache([
    'query_name' => '*',
    'expire' => 120, // sec
]);
```

or you can target specific queries

```
use WPGraphQL\Extensions\Cache\CacheManager;

CacheManager::register_graphql_query_cache([
    'query_name' => 'MySlowQuery',
    'expire' => 120,
]);
```

Field Caching
-------------

[](#field-caching)

Lets say you have a big query fetching various things where most of them are reasonably fast but one of the is too slow. You can target that individual root field with `register_graphql_field_cache()`.

```
use WPGraphQL\Extensions\Cache\CacheManager;

CacheManager::register_graphql_field_cache([
    'query_name' => 'MyBigQuery',
    'field_name' => 'menuItems',
    'expire' => 120, // sec
]);
```

This will start caching the `menuItems` root field on a GraphQL query named `MyBigQuery` for 120 seconds.

Cache Control with Zones
------------------------

[](#cache-control-with-zones)

You can clear all GraphQL caches with `CacheManager::clear()` but if you want to be more specific with cache clearing you must pass in a `zone` property to `register_graphql_query_cache` and `register_graphql_field_cache` and you can clear that zone with `CacheManager::clear_zone($zone)`.

The `zone` is a caching zone the cache will be stored to. Zones are needed because the cached responses are written to multiple cache keys because graphql variables and the current user can change between calls to the same query

The zone can be cleared with `CacheManager::clear_zone()`

```
/**
 * Register cache to a 'menus' zone
 */
CacheManager::register_graphql_field_cache([
    'zone' => 'menus', // 👈
    'query_name' => 'MyBigQuery',
    'field_name' => 'menuItems',
    'expire' => 120, // sec
]);

/**
 * Clear the zone 'menus' when the menus are updated
 */
add_action('wp_update_nav_menu', function () {
    CacheManager::clear_zone('menus');
});
```

You can also share the same zone between multiple caches.

### WP CLI

[](#wp-cli)

The zones can be cleared using the WP CLI too

```
$ wp graphql-cache clear # clear all zones
$ wp graphql-cache clear --zone=menus

```

Measuring Performance
---------------------

[](#measuring-performance)

WPGraphQL Cache comes with very simple build query performance tool which adds a `x-graphql-duration` header to the `/graphql` responses. It contains the duration of the actual GraphQL response **resolving** in milliseconds. When no caches are hit this is the theoretical maximun this plugin can take of from the response times. Everything else is spend in setting up WP and WPGraphQL itself before the GraphQL resolver execution.

If you want to go beyond that you can enable GET requests with Persisted Queries in the [WPGraphQL Lock](https://github.com/valu-digital/wp-graphql-lock) plugin and cache the whole response in your edge server (nginx, varnish, CDN etc.). This will be the absolute best performing cache because the PHP interpreter is not invoked at all on cache hit.

Storage Backends
----------------

[](#storage-backends)

There are couple storage backends availables which can be configured using the `graphql_cache_backend` filter.

```
use WPGraphQL\Extensions\Cache\Backend\FileSystem;

add_filter('graphql_cache_backend', function () {
    return new FileSystem( [
        'base_directory'        => '/custom/path',
        'directory_permissions' => '0770',
        'file_permissions'      => '0660',
    ] );
});
```

### FileSystem

[](#filesystem)

This is the default backend which writes the cache to `/tmp/wp-graphql-cache`. It not super fast but it can perform reasonably when backed by a RAM disk.

### Transient

[](#transient)

This is cache storage backend which writes WordPress transients.

This is a flexible cache storage backend as the true storage can be configured at a platform level via the use of the object cache. By default if no object cache is defined WordPress will store transients as options in the database.

For example a single server environment might use a APC object cache where as a HA environment might have a Memcached or Redis backend.

### OPCache

[](#opcache)

TODO

### Custom Backends

[](#custom-backends)

A custom backend can be also returned as long as it extends from `\WPGraphQL\Extensions\Cache\Backend\AbstractBackend`.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.2% 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 ~84 days

Recently: every ~147 days

Total

8

Last Release

1609d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62e64ab16d2c22b2d02dd123a85135093821bc9f7f3619f38c84227ed93427af?d=identicon)[valu](/maintainers/valu)

---

Top Contributors

[![esamattis](https://avatars.githubusercontent.com/u/225712?v=4)](https://github.com/esamattis "esamattis (108 commits)")[![dre1080](https://avatars.githubusercontent.com/u/303936?v=4)](https://github.com/dre1080 "dre1080 (1 commits)")[![raipatti](https://avatars.githubusercontent.com/u/59355006?v=4)](https://github.com/raipatti "raipatti (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/valu-wp-graphql-cache/health.svg)

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

###  Alternatives

[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)[cheprasov/php-redis-client

Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 6.0

1281.2M21](/packages/cheprasov-php-redis-client)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)

PHPackages © 2026

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