gpt4 book ai didi

firebase - Firebase 托管能否提供来自 Cloud Functions 的缓存数据?

转载 作者:行者123 更新时间:2023-12-03 14:57:58 24 4
gpt4 key购买 nike

假设我在 firestore 中有一个包含 100,000 条内容的数据库。每条内容每月更改一次的可能性不大。我的单页应用程序使用 firebase 托管,使用一个函数从 firestore 检索内容,将其呈现为 HTML,然后将其返回到浏览器。

如果我经常为不那么动态的内容执行此过程,那将浪费我的 Firestore 配额,并且开始累积大量资金。

那条内容如何保存为静态 .com/path/path/contentpage.html 文件要在请求确切路径和查询时提供,而不是每次都通过 firestore/functions 过程?

我的目标是提高速度,减少不必要的 firestore 请求,因为我知道每次读取都要花钱。

谢谢!

最佳答案

当您使用 Firebase Hosting顶部 Cloud Functions for Firebase , 托管可以作为 HTTPS 功能响应之上的边缘缓存层。您可以在 documentation 中阅读有关该集成的信息。 .请特别阅读 managing cache behavior 部分:

The main tool you'll use to manage cache is the Cache-Control header. By setting it, you can communicate both to the browser and the CDN how long your content should be cached. In your function, you set Cache-Control like so:

res.set('Cache-Control', 'public, max-age=300, s-maxage=600');

关于firebase - Firebase 托管能否提供来自 Cloud Functions 的缓存数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47821712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com