cube-js / cube-js/cube

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

Open
#2,368 5 comments 5 reactions 0 assignees View on GitHub
backend:server help wanted
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.