简体   繁体   English

为特定的DatabaseReference设置Firebase.setPersistenceEnabled()

[英]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.

相关问题 查询Firebase DatabaseReference的惯用法是什么? - what is the idiom to query a Firebase DatabaseReference? Android Firebase - 如何将 DatabaseReference 设置为为所有用户生成的推送密钥? - Android Firebase - How do I set DatabaseReference to a generated push key for all users? firebase databasereference没有给出虚拟方法错误 - firebase databasereference gives no virtual method error 不能转换为 com.google.firebase.database.DatabaseReference - cannot be cast to com.google.firebase.database.DatabaseReference 在Android上处理Firebase DatabaseReference updateChildren OnCompletionListener的正确方法 - Right way to handle Firebase DatabaseReference updateChildren OnCompletionListener on Android 在Android上将GeoFire与Firebase结合使用,但找不到DatabaseReference类 - Using GeoFire with Firebase on Android, but can't find the DatabaseReference Class Android-Firebase:代码等效于以快速方式列出所有数据库引用用户 - Android - Firebase: code equivalent to list all users of databasereference as swift Firebase 实时数据库 - DatabaseReference.push().getKey() 是一个时间戳 - Firebase Real Time DB - DatabaseReference.push().getKey() is a TimeStamp com.google.firebase.database.Query 不能转换为 com.google.firebase.database.DatabaseReference - com.google.firebase.database.Query cannot be cast to com.google.firebase.database.DatabaseReference 在Firebase上使用.setPersistenceEnabled(true)时,真的需要.addOnCompleteListener吗? - It's really necessary .addOnCompleteListener when you're using .setPersistenceEnabled(true) on Firebase?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM