skip to Main Content

For a new project we want to experiment with Firebase Database, the idea is to store SEO, Product, User Preferences and so on.

We are expecting that the SEO data will be the bigger space consumer and the client doesn’t need to save this information locally as will be only used for statistical purposes

Is it possible to enable Firebase Database Persistence only on certain nodes and exclude others?

Thanks for your help

2

Answers


  1. Persistence can only be configured all or nothing. This is true for both Realtime Database and Cloud Firestore. There is no granular persistence setting. Please feel free to file a feature request.

    Login or Signup to reply.
  2. To do this you can configure two separate firebase instances – one with persistence turned ON and another one with persistence turned OFF, even if they both point to the same database (or you can configure for several different databases – that exactly what it was created for).

    The example below is in Swift, but I suppose there should be equivalents on other platforms:

    if let path = Bundle.main.path(forResource: firebasePlistFileName, ofType: "plist"), let options = FirebaseOptions(contentsOfFile: path) {
         FirebaseApp.configure(options: options)
         FirebaseApp.configure(name: "DatabaseWithoutPersitence", options: options)
    }
    Database.database().isPersistenceEnabled = true
    if let appWithoutPersistence = FirebaseApp.app(name: "DatabaseWithoutPersitence") {
         Database.database(app: appWithoutPersistence).isPersistenceEnabled = false
    }
    

    When I want to access a database with persistence I address a shared database via Database.database().reference() and in case I need fresh data I refer to the non-persistent one via Database.database(app: FirebaseApp.app(name: "DatabaseWithoutPersitence")!).reference()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search