【发布时间】:2017-07-27 05:47:42
【问题描述】:
我在 Firebase 之上构建了一个 GraphQL API。 API 使用连接到 Firebase 托管的云函数来处理请求。
我的目的是缓存发送到 GraphQL API 的请求的响应。
一个ExpressJS中间件配置如下:
function setCacheHeaders(req, res, next) {
res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
return next();
}
如果我向 API 发送 GET 请求,我会看到它到达 CDN:
X-Cache: HIT
X-Cache-Hits: 1
X-Served-By: cache-lhr6343-LHR
但是,当我发送 POST 请求(这是与 GraphQL 端点交互的常用方式,即使它是只读操作)时,我注意到没有请求访问缓存。但是,响应包含以下标头:
HTTP/1.1 200 OK
Accept-Ranges: bytes
Connection: keep-alive
Content-Length: 311
Content-Type: application/json
Date: Thu, 27 Jul 2017 05:41:02 GMT
Server: nginx
Strict-Transport-Security: max-age=31556926
Vary: Accept-Encoding, Authorization, Cookie
Via: 1.1 varnish
X-Cache: MISS
X-Cache-Hits: 0
X-Served-By: cache-lcy1133-LCY
X-Timer: S1501134062.745716,VS0,VE640
cache-control: public, max-age=300, s-maxage=600
function-execution-id: xg0qjlghrtrv
x-cloud-trace-context: 02434a5f73159e24d949e74026bb8843, 02434a5f73159e24d949e74026bb8843
x-powered-by: Express
是否无法使用 Firebase 托管缓存对 POST 请求的响应?
【问题讨论】:
标签: javascript firebase google-cloud-functions firebase-hosting