Currently I have following scenario.
I have two projects: ASP.NET Core Web API and Xamarin.Forms app. General idea is to have consumer (Xamarin.Forms app) which is getting data from server (Web API).
What I want to implement is caching pattern for the mobile app. Let's say, we're getting some products from the server and then we want to cache them, so next time when use open app he won't re-get all products again.
The problem is coming when these products are updated, then we want our mobile app to always stay with latest data, but still refresh products only if they're updated. For this I've considered using versioning on my database entities (products). For example, first time when app request to get product he will send version
null header, then API will spot it, get from database product and return it with its version, for example
5. After that product could be updated, so version will be increased with one. When app send request to get product again, depending on provided in header version API will get latest data from database or return
304 NotModified status code.
While I was developing this scenario, I've decided to change "int version" to simply "DateTime lastModified", which I find for a little bit more useful.
My struggle is coming when I have scenario with multiple items, let's say I want to get all products from category. Then I am not sure what is the best case for solving that issue. I've considered to expect from consumer to send me collection with product id and last modified, so I can iterate through all of them and check if something has changed. Other option is to expect sending be hash of that collection, so on the server side I can hash searched collection and compare hashes. Third option is, if for each collection I have extra property which is containing last modified, but then I will have one extra column in database (SQL) for each
many relation and then modifying product would require extra code, to find all it's relations and update all properties.
Generally my problem is when it comes to collections.
Still is this good way, for designing application? What I want to achieve, is reduce traffic between server and consumer.
I'm open for any other suggestions!
Thanks in advance!