HTTP Caching | wundergraph
Version: Next

HTTP Caching

WunderGraph gives you HTTP based caching out of the box. Because all Queries get persisted WunderGraph doesn't have to send Queries as POST requests. Due to this WunderGraph can make use of standard HTTP based caching.

The WunderGraph Node itself has an in Memory LRU Cache. In addition we set Cache Control Headers according to the configuration.

This means Browsers are capable of caching responses for public and private (Authentication enabled) APIs. Responses that don't require authentication can also be cached by any HTTP Cache, e.g. Varnish, as well as by Content Delivery Networks like Cloudflare.

To configure Caching for you API have a look at the following picture:


When defining your Operations you have to use the @cache directive to configure Caching for each individual Request.

The "AllCountries" Query has Auth explicitly disabled while caching is enabled. In this case we set the Cache Control headers to "public" which means that the response can be cached by Browsers as well as intermediate Caches like a CDN.

The "AllContinents" query has not explicitly disabled authentication. Responses therefore get the Cache Control header "private" so that only Browsers cache the response while intermediate Caches are disallowed to do so.

The @cache directive also takes a "maxAge" argument to indicate the maximum time in seconds a response will be understood "fresh".

There's an additional "vary" argument which takes a list of Strings which should be used to build a cache key. For each key provided the corresponding HTTP Header will be appended to the cache key.

E.g. if there's a Header "foo" on the Request with the value "bar", "bar" will be appended to the cache key if you supply "foo" as a vary argument.

You can also use "jwt.sub", "jwt.xxx", etc. to append Claims from a jwt to the cache key. This is useful for authenticated requests if you want to cache responses for individual users in case the URL is not containing any user information.


Subscribe to our newsletter to never miss new blog posts or announcements.