At the same time, we don't think developers should have to specify cache hints for every single field in their schema. Our philosophy behind Apollo Server caching is that a response should only be considered cacheable if every part of that response opts in to being cacheable.
This method enables you to get the default cache hint for a particular object type. To use the directive, you must add the following definitions to your server's schema: In your schema (static)Īpollo Server recognizes the directive, which you can use in your schema to define caching behavior either for a single field, or for all fields that return a particular type. These details can vary significantly, even among the fields of a single object type. Whether a cached value is global or user-specific.
How long a cached value should remain valid.Which fields of your schema can be cached safely.Note that when setting cache hints, it's important to understand: You can define field-level cache hints statically in your schema definition or dynamically in your resolvers (or both). You can then use this calculation to support any form of cache implementation you want, such as by providing it to your CDN via a Cache-Control header. When Apollo Server resolves an operation, it calculates the result's correct cache behavior based on the most restrictive settings among the result's fields.