How to handle persistence if my app needs to constantly making GET/POST requests to backend REST-API based web service?
I have a list of cars related to a specific user, that list could be modified from the web app or the iOS app(like adding new car, deleting it from the list or update the image of existing car).
Right now I’m using URLSession for handle the network layer, and FileManager to make data persistent on disk.
Problems I have encountered so far are:
The only way the iOS app to notice any changes on the “Data Source/Backend” is by the user triggering the viewWillAppear in Main Screen/VC that has a table view containing all Cars related to said user.
Everytime viewWillAppear gets triggered a new GET request starts and decode the received response. If there is data received and no errors at all it ALWAYS tries to save it to the .caches directory and then pass the data to the ViewController vars.
But if there is an error on the response. Then the view loads it’s data from the disk.
The process is too slow because is constantly using data and disk resources.
But what I can’t figure out is, how should abstract data persistence from networking and save/update/delete the received data in another thread or moment while the app is running(or not?).
And if the user makes a new change to the car list or specific car how the persistence logic should be approached?
From updates (crUd) right now I’m only making a POST request to the backend and deleting the related file. If the user tries to list all cars again another GET request start and the process is repeated