Distributed caching for the Apollo Router
With GraphOS Enterprise
⚠️ This is an Enterprise feature of the Apollo Router. It requires an organization with a GraphOS Enterprise plan.
If your organization doesn't currently have an Enterprise plan, you can test out this functionality by signing up for a free Enterprise trial.
If you have multiple Apollo Router instances, those instances can share a Redis-backed cache for their query plans and automatic persisted queries (APQ). This means that if any of your router instances caches a particular value, all of your instances can look up that value to significantly improve responsiveness.
For more details on query plans and APQ, see the article on in-memory caching.
To use this feature:
- You must have a Redis cluster (or single instance) that your router instances can communicate with.
- You must have a GraphOS Enterprise plan and connect your router to GraphOS.
How it works
Whenever a router instance requires a query plan or APQ query string to resolve a client operation:
- The router instance checks its own in-memory cache for the required value and uses it if found.
- If not found, the router instance then checks the distributed Redis cache for the required value and uses it if found. It also then replicates the found value in its own in-memory cache.
- If not found, the router instance generates the required query plan or requests the full operation string from the client for APQ.
- The router instance stores the obtained value in both the distributed cache and its in-memory cache.
Distributed query plan caching
To enable distributed caching of query plans, add the following to your router's YAML config file:
supergraph:query_planning:experimental_cache:redis:urls: ["redis://..."]
The value of urls
is a list of URLs for all Redis instances in your cluster. These can be redis://
or rediss://
URLs.
⚠️ You should specify your Redis URLs via environment variables and variable expansion. This prevents your Redis URLs from being committed to version control, which is especially dangerous if they include authentication information like a username and/or password.
Distributed APQ caching
To enable distributed caching of automatic persisted queries (APQ), add the following to your router's YAML config file:
apq:router:cache:redis:urls: ["redis://..."]
The value of urls
is a list of URLs for all Redis instances in your cluster. These can be redis://
or rediss://
URLs.
⚠️ You should specify your Redis URLs via environment variables and variable expansion. This prevents your Redis URLs from being committed to version control, which is especially dangerous if they include authentication information like a username and/or password.