Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Nic Huang
Courses Plus Student 10,573 PointsSelf-destructing app Ribbit: cache policy
I want to do some cache functionality in this App, but I'm not sure what's the best way to implement and have some questions on it.
Here is what I want to do:
I want to cache all friends, including string data and even profile picture , so that my app doesn't have to query data all the time from Parse.com.
As for messages, I think there is no need to cache it because it will self-destruct.
The questions are:
- When I shut down my app and open it, my app will cache data within it. But how does it know if there is new data coming on Parse.com? Do I have to start to query Parse to cross-check whether the two arrays (one from cache, the other from parse) are the same? If so, what's the best way to do this? core data or Parse's cache functionalities?
Please point me a direction or a sample. I have been puzzled by this for months
I really want to know how messenger app like WhatsApp deal with cache and what ways it stores its contacts and chat history.
Thanks
1 Answer
Amit Bijlani
Treehouse Guest TeacherThis is a great question and comes up often when building real world apps. You actually have two issues at hand. One is caching and the other is syncing.
Caching
Parse provides some caching so if you fire the same query without a network connection it should provide you with objects from the cache. If you want to keep all the data local and query only when you have new data then you would have to build your own cache using Core Data.
Syncing
Implementing a sync is a bit more complex.
Simple scenario: Parse -> Device Whatever is on parse ends up being on the device. This is a one way sync.
Complex scenario Device1 <-> Parse <-> Device This is a multi-device sync. If you use the app on multiple devices then you can somehow sync the state on all the devices using Parse.
Let's take the Simple scenario. Each time you open up the app you can query Parse for data. You can have a column called "Downloaded" and once you download and import that data using Core Data you can turn set the Downloaded flag.