缓存对 Firebase 函数发出的 POST 请求的响应

洛朗

我在 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 请求的响应?

石达之

不。POST 不是幂等的,并且由于您无法访问 Fastly(Firebase 托管 CDN 提供商)清漆规则,您甚至无法“破解”来实现它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章