[英]Set Firebase.setPersistenceEnabled() for particular DatabaseReference
I have a ListenerForSingleValueEvent
that checks for a particular value in the database before a particular operation can be carried out. 我有一个
ListenerForSingleValueEvent
,它可以在执行特定操作之前检查数据库中的特定值。 But because .setPersistenceEnabled
is true, it uses the value from the disk cache which could be sometimes wrong and not updated and causes the user to perform the task even though the user should not be able to. 但是,因为
.setPersistenceEnabled
为true,所以它使用磁盘缓存中的值,该值有时可能是错误的且未更新,即使用户不能执行该操作,也会导致用户执行任务。
I could set .setPersistenceEnabled
to false, but I have a chat feature and it would be very user unfriendly to reload messages each time the user opens the app. 我可以将
.setPersistenceEnabled
设置为false,但是我具有聊天功能,并且每次用户打开应用程序时重新加载消息对用户来说都是非常不友好的。 Is there a way I could set .setPersistenceEnabled
for only some particular Database References and reload all other references each time or vice-versa, ie, .setPersistenceEnabled
for all Database References and reload particular references each time. 有没有一种方法可以为仅某些特定的数据库引用设置
.setPersistenceEnabled
并每次都重新加载所有其他引用,反之亦然,即为所有数据库引用设置.setPersistenceEnabled
并每次重新加载特定的引用。 Thanks for the help. 谢谢您的帮助。
Sounds like you might be able to use Query.keepSynced() : 听起来您可能可以使用Query.keepSynced() :
By calling
keepSynced(true)
on a location, the data for that location will automatically be downloaded and kept in sync, even when no listeners are attached for that location.通过在某个位置上调用
keepSynced(true)
,即使该位置未连接任何侦听器,该位置的数据也将自动下载并保持同步。 Additionally, while a location is kept synced, it will not be evicted from the persistent disk cache.此外,在位置保持同步的同时,不会从持久磁盘缓存中将其移出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.