Mobile Application Caching - HunYahiko/smart-parking-system GitHub Wiki

Mobile Application Caching

Room Persistance Library.

Android offers a great library to work with databases in Android applications. It is an abstract layer over SQLite, whose configuration is pretty painful to do.
It is easy to be understood by Spring Framework users, since most of annotations are pretty similar.

Parking Location caching.

Since we needed some caching for our assignments, I decided to go with parking locations. Parking location will rarely move their location, which means we can save them in our database.

First I declared the entity, ParkingLocation.
For that entity, I declared it's DAO interface, which contains the CRUD operations available.

To actually create our database, I used Room builders. Room provides two types of databases: in-memory and saving in phone memory.
Since create a database is costly, I used Singleton pattern with lazy initialization for database creation. Working with phone stored database is very slow, this is why in-memory was preffered.

Since database operation + initialization can't be done on main thread, we integrated RxAndroid to our database DAO as well.
All of the operations use classes from reactive IO, which allows us to perform async operations and be notified whenever they are finished.

⚠️ **GitHub.com Fallback** ⚠️