Fetching strategies - Do not fetch redundant data. ETags, Lastmodified, own API? Recommendations, practice?

I am developing an Xcode app with a job feed, with profile view, with chat eg. I fetch using federatet queries to my microservices thru Apollo Router. Infront of the Apollo Router i Have a Kong that adds a X user ID, that the microservices use for personalized feed and other user info. The info is stored with SwiftData. My thought is that i should add a better way of controlling when i need to fetch. I have a “lastupdateAPI” with different entities (profile, profile picture eg). So when nothing has changed we do not fetch. But rather then using a own API for this, isnt ETag better? Or is it any other recommendations with Xcode Swiftui. Good strategies for not fetching what i already have?

Answered by DTS Engineer in 825329022

If you intent is to detect a change on your SwiftData store without adding your own data structure, consider observing ModelContext.disSave notification and looking into the SwiftData history from there. The following technical resources cover the what and how:

The discussion in the following posts may help as well:

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

that's what ETag is used for. Might be a bit fragile depending on how requests and responses are structured but no reason why ETag shouldn't work. Obviously implementing your own solution provides more flexibility.

If you intent is to detect a change on your SwiftData store without adding your own data structure, consider observing ModelContext.disSave notification and looking into the SwiftData history from there. The following technical resources cover the what and how:

The discussion in the following posts may help as well:

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Fetching strategies - Do not fetch redundant data. ETags, Lastmodified, own API? Recommendations, practice?
 
 
Q