This SQLDelight caching mechanism project is simple application which interacts with simple database. Application displays list of persons fetched from remote and local database. Application allows you to add/delete Persons in online & offline mode. When added/deleted while offline values gets cached into local database and after application restart if device is online values are added/ deleted in server.
This application is built in Android Studio version 2020.3.1 (Artic Fox) using :
Here you can see empty PersonsDatabase in App Inspection provided by Android Studio and empty PersonsDatabase server in MongoDB Compass
Application where 2 persons are added in online mode where "done" icon is in green and one person is added in offline mode where icon is red. In App Inspection you can see database with 3 Persons and for the last person Synced atrribute is false ("0"), that means that current person is not synced to remote database
For this case MongoDB Compass shows that there are only 2 persons, that is because person is stored in local database and waits until it gets synced
After internet is connected and application restarted then person gets Synced to server and isSynced atribute is true ("1").
For delete functionality there is seperate table, when person is deleted offline persons id gets stored in this table, and after internet connection is restored this Id gets deleted from remote database.
Ugis Ozols - [email protected]
LinkedIn - www.linkedin.com/in/ozols-ugis
Project Link - https://github.com/OzolsUgis/SQLDelightCachingMech