'Android automatic sync between in-Memory and persistence Room database

I am building an app using Room as Database. I used the Repository pattern so using one call, I can access memory, database and the api call.

For the memory part, I am just using a data class and inject it. I was asking myself if it make sense to keep it.

I am not managing a ton of data but I save them into Room for data persistence.

So I was thinking getting ride of my data class and use Room in-Memory instead.

Is there a way to have my in-memoryDB and persistenceDb (same structure) automatically sync so I can access just the inMemory one knowing that the persistent one is sync and if the app is killed, I can trigger at launch a sync between inMemory ad Persistent

            val instance = Room.databaseBuilder(
                context.applicationContext,
                CarShadowRoomDatabase::class.java,
                "database"
            )
                .fallbackToDestructiveMigration()
                .build()

and use inMemoryDatabaseBuilder to create my DB in memory.

Any idea ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source