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

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

matepaiva/wp-graphql-cache
==========================

Flexible caching framework for WPGraphQL

v0.0.9(3y ago)0147GPL-2.0-or-laterPHP

Since Jun 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/matepaiva/wp-graphql-cache)[ Packagist](https://packagist.org/packages/matepaiva/wp-graphql-cache)[ RSS](/packages/matepaiva-wp-graphql-cache/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (1)Dependencies (12)Versions (2)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('/custom/path');
});
```

### 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.

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

19

—

LowBetter than 9% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

1114d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/781670?v=4)[Marcelo Paiva](/maintainers/mpaiva)[@mpaiva](https://github.com/mpaiva)

---

Top Contributors

[![matepaiva](https://avatars.githubusercontent.com/u/9984086?v=4)](https://github.com/matepaiva "matepaiva (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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