When building offline-first mobile apps, you rely heavily on a cache. When data is pulled from a remote storage API, you should save this data to the device's cache so the next time your app user goes to open your app, you show them cached data instead of a "Loading...Please wait" message while your app pulls new data from the remote storage API. We all hate these loading screens. Building offline-first mobile apps is the way to remove the need for them.
This makes sense to use cached data, but I understand that it can be quite difficult to do. I am here today to talk about why it is difficult and how it just got a whole lot easier!
Managing the state of your cache is a pain.
When you are building an offline-first mobile app, or any app that stores data on the device's storage, managing the state of that cached data is difficult. The data set could be empty, it could have data in it, it could be old data that needs to be updated, it could have yet to ever be fetched in the first place.
Besides parsing the cached data to see what state the data set is in, managing the data's state is a whole other pain. What if the cached data is too old? You need to kick off a network API call to fetch fresh data, show in the UI of the app that fresh data is being fetched, and after the fetch is complete you need to save the data to a cache and then update the UI to indicate the fetch is done and show the fresh cached data. Putting all of this together is not super complex, but it is a pain. Especially for each and every different data set in your app!
Teller (Android version, iOS version) is a new open source Android and iOS library to help you create offline-first mobile apps. The goal of Teller is to make fetching and caching data so easy that it's stupid not to cache your data!
What does Teller do?
Teller does two things. (1) It parses your cached data to determine what state the data set is in. It also (2) manages the data to make sure that the cached data is always fresh.
All you need to do to use Teller is to define how to save data, query cached data, and fetch fresh data in a
Repository subclass, then observe the repository in the UI of your application. Teller manages everything else for you. Your data will stay up-to-date and will continuously deliver the state of the data to your listener to update the UI for your user.
Teller continuously notifies you about the state of your data in 2 simple steps.
Building offline-first mobile apps with Teller.
A couple of months ago, I wrote about my mission to make building offline-first mobile apps stupid easy. I have said it once and I'll say it again: I believe every app should be offline-first. But yet, it's still a hard task to do.
To make building offline-first mobile apps easier, I set out to build the open source Wendy (Android, iOS) library. Wendy is an awesome library that helps you build offline-first mobile apps by syncing data stored on my user's devices with remote cloud storage.
Wendy solves a big pain point when building offline-first mobile apps when it comes to syncing device storage with remote cloud storage. What about the other way around?
Wendy is not for fetching data from remote cloud storage and syncing that with my user's device storage. You know what is really good at this though...? Yup, Teller.
Wendy was step 1 out of 2 of my mission to make building offline-first mobile apps stupid easy. Teller is step 2 out of 2.
Storing data to a cache is easy with databases (SQLite, CoreData, Realm), key-value storage (NSUserDefaults, KeyStore, SharedPreferences), and file storage. Fetching data from a remote storage API is easy (Retrofit, Alamofire, Moya). You know how to build mobile apps that save data and fetch fresh data from remote storage. It's connecting those pieces that is difficult. Teller and Wendy are here to fix that.
Wendy and Teller are both currently in alpha stage for both Android and iOS. Both Wendy and Teller are running in production today in apps that I have built, but there is still a lot of work to do to make these libraries helpful for more then just me.
Check out all of the GitHub open source library repos below. Read the documentation there to get started using them in your apps today. Follow me on Twitter, add my blog to your Feedly, or join my blog newsletter to get notified about future development on Teller and Wendy.