Adds an in-process or Redis-based caching layer to Mercurius GraphQL server, with deduplication via async-cache-dedupe. Current stable version is 8.0.0, released in 2025. Supports fine-grained per-resolver TTL, stale-while-revalidate, and invalidation. Fully compatible with federation. Unlike generic caching solutions, it integrates directly with Mercurius lifecycle and provides policy-based caching for individual queries or all resolvers. Recommended for production GraphQL APIs needing to reduce load on resolvers with acceptable data staleness.
npm install mercurius-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Register Mercurius-Cache with a 10-second TTL, caching only the 'add' resolver.
Explicitly set ttl to a positive number to enable caching.
Move stale to policy-level configuration where needed.
Use only 'all: true' or only 'policy', never both.
Use Redis storage with shared client for a global cache.
Ensure resolvers return serializable JSON objects.
Ensure app.register(mercurius, ...) is called before app.register(cache, ...).
Use `const cache = require('mercurius-cache');` instead of `const { cache } = require('mercurius-cache');`.Provide a valid ioredis client: `options.client = new Redis()`.