LinkedIn Makes Rocket Data Open Source So You Can Cache Data in Your iOS Apps Too
Thursday, August 4, 2016
Last year, LinkedIn began rewriting the LinkedIn flagship mobile application. The existing app had a number of challenges and hadn’t received a significant overhaul in some time. So we wanted the new version to not only look and feel updated, but also to have powerful infrastructure backend to support it.
As a part of that effort, we wanted a caching system that would present content to the user while data was loading from the network. Core Data, a commonly used modeling and database framework provided by Apple, offers one potential solution. Core Data is a powerful framework, but it pays for its power with complexity, and the framework is notorious for crashing applications when something goes wrong.
We also wanted to use immutable models, and Core Data’s programming model relies on mutability. We then looked at some other options, like a simple URL cache, Realm, or just serializing the models to disk, but none of these solutions addressed our requirements.
So, we decided to develop our own caching solution, building Rocket Data, which is a non-blocking, immutable model management system with a persistent synchronization layer. And we recently announced that we open sourced it (Rocket Data on Github) as well.
Rocket Data has a simple API which easily hooks up to key-value stores and can use any cache. Each view controller has a reference to one or more data providers. There are two types of data providers: regular data providers and collection data providers. The data is easy to consume with simple accessors in both providers and access to the data is instant, since the models are always kept in memory.
Here’s an example application run to show how data flows through Rocket Data:
- The view controller calls loadFromCache on the data provider. This call is asynchronous so it will not block the main UI thread. When the data returns, the view controller is notified and it will rerender.
- The view controller receives fresh data from the server. The view controller sets this data on the data provider. The data provider then lazily propagates this to the cache and Consistency Manager, again on a background thread.
- Later in the application execution, a model is changed which affects our view controller. The Consistency Manager will notify the data provider which will update its data and notify the view controller so it can rerender.
By using Rocket Data, we’ve been able to easily add caching to all features within the new LinkedIn mobile app with very little additional work from developers. The cache and data providers are automatically kept consistent across screens, and we’ve never needed to add code for any migrations.
We believe other products could benefit from Rocket Data’s flexibility to work with multiple modeling and caching solutions and are looking forward to hearing how it is used by the community.
Read more: https://engineering.linkedin.com/blog/2016/07/rock...
This content is made possible by a guest author, or sponsor; it is not written by and does not necessarily reflect the views of App Developer Magazine's editorial staff.
Flagging your new app features with more visibility Tuesday, July 17, 2018
Emojis inside app push alerts significantly influence engagement says Leanplum Tuesday, July 17, 2018
Startups to compete at Fog World Congress 2018 Tuesday, July 17, 2018
Making your apps accessible to those with disabilities Monday, July 16, 2018
Mobile blockchain SDK helps devs integrate the new tech Monday, July 16, 2018
Stay UpdatedSign up for our newsletter for the headlines delivered to you