Monday, 4 November 2019

Firestore still retrieving documents from cache even though I've disabled persistence

My Firestore is still retrieving documents from cache even though I've explicitly told it not to:

class MainActivity : AppCompatActivity() {

    val db = FirebaseFirestore.getInstance()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val dbSettings = FirebaseFirestoreSettings.Builder().setPersistenceEnabled(false).build()
        db.firestoreSettings = dbSettings

Above is my launcher activity where I set the Firestore settings.

In my fragment I perform a GeoFirestore GeoQuery:

class MapFragment : Fragment() {
    val instances = FirebaseFirestore.getInstance().collection("instances")
    val geoFirestore = GeoFirestore(instances)
    lateinit var nearbyDocs: GeoQuery

    private fun searchNearby(){
        nearbyDocs = geoFirestore.queryAtLocation(currentLocation, 1.0)
        nearbyDocs.addGeoQueryDataEventListener(object : GeoQueryDataEventListener {

            override fun onDocumentEntered(documentSnapshot: DocumentSnapshot, location: GeoPoint) {
               Log.d(TAG, "onDocumentEntered: user1: ${documentSnapshot.getString("user1")?.substring(0, 3)} | docId: ${documentSnapshot.id.substring(0, 5)} | fromCache: ${documentSnapshot.metadata.isFromCache}")
               Log.d(TAG, "isPersistanceEnabled2: ${db.firestoreSettings.isPersistenceEnabled}")
            }
    }

This is what it logs:

onDocumentEntered: user1: 0X6 | docId: lPLFf | fromCache: true
isPersistanceEnabled2: false

This doesn't make sense - I'm receiving cached documents even though my persistence is turned off.

Any idea what the problem is?



from Firestore still retrieving documents from cache even though I've disabled persistence

No comments:

Post a Comment