跨多个Azure Function实例共享对象 [英] Sharing an object across several Azure Function instances

查看:48
本文介绍了跨多个Azure Function实例共享对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个需求,我们需要在其中存储一个可以被函数的多个实例访问和使用的对象,请告知实现此目的的最佳方法是什么.

We have a requirement where we need to store a Object which can be accesses and used by multiple instance of the function, please advise what would be the best way to achieve this.

推荐答案

大多数情况下,所有函数执行都在同一进程中运行,因此您可以可以使用静态类成员来共享状态功能实例.但是,这是不可靠的.该进程可以随时关闭,或者您的功能可以扩展到跨多个VM的多个进程,这意味着某些功能将看到静态数据的一个副本,而其他功能将看到不同的副本.因此,静态变量实际上仅可用作尽力而为的瞬时缓存.

Most of the time all your function executions are running in the same process, so you could use static class members to share state across function instances. However, this is not reliable. The process could go down at any time, or your function could be scaled out to multiple processes across multiple VMs, which means some functions will see one copy of the static data while others see a different copy. For that reason, static variables are really only useful as a best-effort transient cache.

如果要在函数实例之间可靠地共享对象,则需要将对象序列化到某些外部数据存储(例如Redis),或将对象序列化到本地文件系统,该文件对所有实例都始终可用.您的功能.

If you want to share objects between function instances reliably, you'll either need to serialize your objects to some external data store, like Redis, or serialize your objects to the local file system, which is always available to all instances of your function.

这篇关于跨多个Azure Function实例共享对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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