The given code block is called twice by .fetch() when the cache policy is set to .returnCacheDataAndFetch
@tlextrait Please read below Cache policy.
public enum CachePolicy {
/// Return data from the cache if available, else fetch results from the server.
case returnCacheDataElseFetch
/// Always fetch results from the server.
case fetchIgnoringCacheData
/// Return data from the cache if available, else return nil.
case returnCacheDataDontFetch
/// Return data from the cache if available, and always fetch results from the server.
case returnCacheDataAndFetch
}
If you use the returnCacheDataAndFetch Then It will return first time from cache and second time from server. If want to data only from server fetchIgnoringCacheData or If want to data only from cache returnCacheDataDontFetch
Right but that comment didn't imply at all that my callback would be called more than once. It sounded more like I'd get data from cache, but that in parallel a data fetch would also update the cache afterwards.
Would be nice if it only called the callback a second time if the data has changed
I'll have to take a look at this - right now it seems like the best course of action is to actually document that this will return twice, because I think making it only return if the data's changed would break some existing implementations.
Documentation of this as expected behavior was added and shipped as part of 0.13.0 - gonna close this out, thanks for bringing this up!
Most helpful comment
Would be nice if it only called the callback a second time if the data has changed