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

查看:79
本文介绍了附加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磁盘,因此任何文件都可以写入n将从分配给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.

另请参见:

  • Write temporary files from Google Cloud Function
  • the documentation on cleaning up temporary files
  • Firebase cloud function [ Error: memory limit exceeded. Function invocation was interrupted.] on youtube video upload

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

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