ViewModels: Persistence, onSaveInstanceState(), Restoring UI State and Loaders
Lyla Fujiwara

Awesome write up, thank you! I hope you’ll answer the rest of concerns from in the next articles.

I have a few questions that are more about the Repository part than about ViewModels.

In the music search example, suppose the app is fetching the music from an online storage (like Google Play Music). What exactly should I persist in a database when saving a search query?

Should I have a table listing all the search queries and song IDs that matched, but fetch the song metadata like name and artist from the network each time? Should I cache metadata about each and every song that I ever queried that metadata for from the server (to display in the UI for whatever reason)? What do I do to the cache, how do I limit its growth?

Finally, should I try to perform every action (like search) both locally (in the cached entries) and online?

The relevant excerpt from the Guide to Architecture Components is:

Persist as much relevant and fresh data as possible so that your app is usable when the device is in offline mode. While you may enjoy constant and high speed connectivity, your users might not.
Your repository should designate one data source as the single source of truth. Whenever your app needs to access this piece of data, it should always originate from the single source of truth.
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.