Overview of GraphQL ObjectCache
masterGraphQL::Enterprise::ObjectCache is an application-level cache for GraphQL-Ruby servers. It improves performance by storing a cache fingerprint for each object in a query and serving cached responses as long as those fingerprints remain unchanged. This reduces latency for clients and decreases the load on your database and application server.
How it works:
- Fingerprinting: Before running a query, it generates a fingerprint using
GraphQL::Query#fingerprintandSchema.context_fingerprint_for(ctx). - Cache Lookup: It checks the backend for a matching fingerprint.
- Validation: If a match is found, it fetches the previously visited objects and compares their current fingerprints to the cached ones. It also verifies
.authorized?for each object (unless re-authorization is explicitly disabled). - Cache Miss/Update: If no match is found or fingerprints differ, the query is re-evaluated. During execution,
ObjectCachecollects the IDs and fingerprints of encountered objects, then writes the new result and fingerprints to the cache.