附加 firebase 云函数或从云函数调用缓存其数据 [英] Attach firebase cloud function or cache its data from cloud function call

查看:24
本文介绍了附加 firebase 云函数或从云函数调用缓存其数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个前端组件,它由一个图表和几个不同的过滤器组成,允许用户按数据类型进行过滤.但是,他们过滤的数据比较大,所以我不想将它们全部加载到网页中,而是让 firebase 云功能来处理过滤.问题是用户在使用这个组件时通常会做一堆过滤,所以云功能重复下载必要的数据是没有意义的.有没有办法将云函数附加"到调用并使其更新而无需重新检索数据,或者如果这不可能,则以某种方式将检索到的 Firebase 数据缓存到云函数可访问的某个地方?

I have a frontend component that consists of a chart and several different filters that allow users to filter by data type. However, the data that they are filtering is relatively large, and so I do not want to load all of it into the webpage, and instead have a firebase cloud function handle the filtering. The issue is that users will usually do a bunch of filtering while using this component, so it does not make sense for the cloud function to repeatedly download the necessary data. Is there a way to "attach" the cloud function to the call and have it update without having to re-retrieve the data, or to somehow cache the retrieved firebase data somewhere accessible to the cloud function if this is not possible?

exports.handleChartData = functions.database.ref("chartData").onCall((data, context) => {
    // can I cache data here somehow
    // or can I have this function read in updates from user selected filters
    // without having to retrieve data again?
}

推荐答案

可以将数据写入本地/tmp磁盘.请注意:

You can write data to the local /tmp disk. Just be aware that:

  • 无法保证下次数据会在那里,因为实例会根据需要向上和向下旋转.因此,您需要在每次调用时检查该文件是否存在,并准备好在它尚不存在时创建它.
  • /tmp 磁盘空间是 RAM 磁盘,因此写入其中的任何文件都将从您为 Cloud Functions 容器分配的内存中取出.
  • 您无法可靠地让侦听器在调用期间保持活动状态,因此您将无法更新缓存.
  • There is no guarantee that the data will be there next time, as instances are spun up and down as needed. So you will need to check if the file exists on each call, and be ready to create it when it doesn't exist yet.
  • The /tmp disk space is a RAM disk, so any files written there will come out of the memory you've allocated for your Cloud Functions containers.
  • You can't reliably keep listeners alive across calls, so you won't be able to update the cache.

另见:

这篇关于附加 firebase 云函数或从云函数调用缓存其数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆