ios - PromiseKit implement cache and fetch feature -
i trying implement caching layer extension promisekit. can fetch data cache->doaction , refreshdata network calls->doaction. 1 of solutions found below:-
func fetch() -> promise<data, promise<data>> { return promise { fulfill, reject in let fresh = urlsession.get(url) let cache = data(contentsoffile: cachepath) fulfill((cache, fresh)) } } fetch().then { cacheddata, freshdata -> promise<data> in if let data = cacheddata { update(data: data) } return freshdata }.then(execute: update)
is there better way solve problem?
Comments
Post a Comment