cube-js/cube

Option to add cache control headers based on `refreshKey` values

Open

#2,368 opened on Mar 14, 2021

View on GitHub
 (5 comments) (5 reactions) (0 assignees)Rust (19,563 stars) (1,965 forks)batch import
backend:serverhelp wanted

Description

I want to replace a custom-build, public query API by Cube.js. The current API server makes heavy use of HTTP caching. Because it is behind 2 proxies (Cloudflare + nginx) and the requests have a very high cache hit ratio, I am able to serve a high volume of requests per second with a small server.

Using the vanilla Cube.js client, I can see that a response from the Cube.js server has an ETag header and the client sends If-None-Match accordingly on the next request - which would be great for caching. Unfortunately though, the response does not set Cache-Control, causing it to bypass/miss both caches, returning the full JSON. To reproduce, open http://cubejs-stripe-dashboard-example.s3-website-us-west-2.amazonaws.com/ in Chrome and check the network tab. All requests have status 200 (instead of 304) and the header x-cache: Miss from cloudfront.

For my app I'd like to set Cache-Control: public, max-age=60 because my data is not realtime and a cache duration of 60s reduces the maximum amount of cache misses per unique query to 1 per minute. stale-while-revalidate=…, stale-if-error=… would be nice to have too.

I checked the server's source code and it does not seem to be possible to set custom server headers with the new Docker-based architecture.

Contributor guide

Option to add cache control headers based on `refreshKey` values · cube-js/cube#2368 | Good First Issue