Why do I see "No cache policy was defined for this operation" in a sample trace?

Have more questions? Submit a request

This message appears when there are no Cache-Control HTTP headers in the response from the operation. These are set in Apollo Server via the @cacheControl directive.

sample_trace.png

To use the @cacheControl directive, you must add the following definitions to your server's schema:

enum CacheControlScope {
    PUBLIC
    PRIVATE
}

directive @cacheControl(
    maxAge: Int
    scope: CacheControlScope
    inheritMaxAge: Boolean
)   on FIELD_DEFINITION | OBJECT | INTERFACE | UNION

Whenever Apollo Server sends an operation response that has a non-zero maxAge, it includes a Cache-Control HTTP header that describes the response's cache policy.

The header has this format: Cache-Control: max-age=60, private

If you run Apollo Server behind a CDN or another caching proxy, you can configure it to use this header's value to cache responses appropriately.

You can find more information on caching here.

Articles in this section

Was this article helpful?
0 out of 0 found this helpful
Share

Comments

0 comments

Please sign in to leave a comment.