PHPackages                             graycore/magento2-graph-ql-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. graycore/magento2-graph-ql-cache

ActiveMagento2-module[Caching](/categories/caching)

graycore/magento2-graph-ql-cache
================================

A Magento 2 module that modifies the built-in GraphQlCache FPC.

0.0.4(5mo ago)121.5k↓39.7%1MITPHPCI passing

Since Jul 25Pushed 5mo agoCompare

[ Source](https://github.com/graycoreio/magento2-graph-ql-cache)[ Packagist](https://packagist.org/packages/graycore/magento2-graph-ql-cache)[ GitHub Sponsors](https://github.com/graycoreio)[ RSS](/packages/graycore-magento2-graph-ql-cache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (6)Used By (0)

graycore/magento2-graph-ql-cache
================================

[](#graycoremagento2-graph-ql-cache)

The Graycore GraphQL Cache module provides a structured mechanism for managing and applying cache lifetimes (TTLs) for Magento 2 GraphQL queries. It allows resolvers to contribute dynamic TTL values based on business logic, such as future dates, promotions, or entity validity. These TTLs are then automatically applied to the response as cache-control headers, enabling full-page caching and CDN integration for GraphQL endpoints.

[![Packagist Downloads](https://camo.githubusercontent.com/f2f40fd1dbb6efd862170dcc6a2e69d3f1c4efb35a5df24a87c5ce0cb3c3bf37/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f67726179636f72652f6d6167656e746f322d67726170682d716c2d63616368653f636f6c6f723d626c7565)](https://packagist.org/packages/graycore/magento2-graph-ql-cache/stats)[![Packagist Version](https://camo.githubusercontent.com/cffdafb0650575ecca6639bb95b6781d0a554a07d1cfa3e7654842da1908917c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67726179636f72652f6d6167656e746f322d67726170682d716c2d63616368653f636f6c6f723d626c7565)](https://packagist.org/packages/graycore/magento2-graph-ql-cache)[![Packagist License](https://camo.githubusercontent.com/6dc7f08283eb3d93bf325b5d2c85222a41394a2b119e89ae6a98a8dd9c707fe5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f67726179636f72652f6d6167656e746f322d67726170682d716c2d6361636865)](https://github.com/graycoreio/magento2-graph-ql-cache/blob/main/LICENSE)

Use Case
--------

[](#use-case)

This module is ideal for Magento stores that want to:

- Dynamically cache GraphQL queries based on data freshness
- Improve GraphQL performance with edge caching/CDNs
- Respect TTLs for time-sensitive data (e.g. flash sales, scheduled promotions, expiring inventory)

Key Features
------------

[](#key-features)

- **Resolver-Driven TTL Aggregation** - Resolver code can dynamically register TTLs using ResolverTtlStoreInterface, either with explicit seconds or based on future dates (with support for start-of-day and end-of-day cutoffs).
- **Automatic Cache Header Population** - This plugin will intercept GraphQL response rendering and applies the minimum TTL collected during the query lifecycle, enabling fine-grained cache-control behavior for GraphQL results.
- **Supports Flexible Input** - TTL input can be an integer, a DateTimeImmutable object, or a string (auto-parsed using the current store’s timezone).
- **Integration with Magento’s GraphQlCache system** - Honors and respects Magento's existing CacheableQuery mechanisms, enhancing them with automatic TTL computation.

Install
-------

[](#install)

```
composer require graycore/magento2-graph-ql-cache
bin/magento module:enable Graycore_GraphQlCache
bin/magento setup:upgrade
```

Usage
-----

[](#usage)

The primary mechanism that you interact with after installation is the `Graycore\GraphQlCache\Api\ResolverTtlStoreInterface`.

```
declare(strict_types=1);

namespace Vendor\Module\Model\Resolver;

use Graycore\GraphQlCache\Api\ResolverTtlStoreInterface;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

class VendorResolver implements ResolverInterface
{

    public function __construct(
        private ResolverTtlStoreInterface $ttlStore
    ) {}

    /**
     * @inheritDoc
     */
    public function resolve(
        Field $field,
        $context,
        ResolveInfo $info,
        array $value = null,
        array $args = null
    ) {
        $this->ttl->add(300); // raw seconds
        $this->ttl->addForDate('2025-08-01T12:00:00'); // string or DateTimeImmutable
        $this->ttl->addForStartDate($date); // uses midnight of the provided date
        $this->ttl->addForEndDate($date);   // uses 23:59:59 of the provided date

        return $value;
    }
}
```

Upgrading
---------

[](#upgrading)

- [Semver Policy](https://semver.org/)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance73

Regular maintenance activity

Popularity29

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 76.9% 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 ~71 days

Total

3

Last Release

154d ago

### Community

Maintainers

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

---

Top Contributors

[![damienwebdev](https://avatars.githubusercontent.com/u/9029654?v=4)](https://github.com/damienwebdev "damienwebdev (10 commits)")[![gray-bot](https://avatars.githubusercontent.com/u/120588553?v=4)](https://github.com/gray-bot "gray-bot (3 commits)")

### Embed Badge

![Health badge](/badges/graycore-magento2-graph-ql-cache/health.svg)

```
[![Health](https://phpackages.com/badges/graycore-magento2-graph-ql-cache/health.svg)](https://phpackages.com/packages/graycore-magento2-graph-ql-cache)
```

###  Alternatives

[lizardmedia/module-varnish-warmer

Varnish Cache Warmer Magento2 module by Lizard Media

6276.8k](/packages/lizardmedia-module-varnish-warmer)[vendic/module-optimize-cache-size

Magento 2 extension that reduces the number of cache keys by removing catalog\_product\_view\_id\_, catalog\_product\_view\_sku\_, catalog\_product\_view\_attribute\_set\_, catalog\_category\_view\_id\_ layout handles by default

3453.6k](/packages/vendic-module-optimize-cache-size)[litespeed/module-litemage

LiteMage Full Page Cache for LiteSpeed Web Server

3254.8k](/packages/litespeed-module-litemage)[redchamps/module-easy-cache-clean

Clean invalidated cache(s) easily in a Magento 2 store

2838.0k](/packages/redchamps-module-easy-cache-clean)[yireo/magento2-autoflushcache

2813.5k](/packages/yireo-magento2-autoflushcache)

PHPackages © 2026

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