nalexn / clean-architecture-swiftui

SwiftUI sample app using Clean Architecture. Examples of working with CoreData persistence, networking, dependency injection, unit testing, and more.
MIT License
5.74k stars 698 forks source link

Image caching #26

Closed NeverwinterMoon closed 4 years ago

NeverwinterMoon commented 4 years ago

Hi!

Some time ago, you've swapped your own implementation of file/in memory caching in favour of URLSessionConfiguration caching.

The latter approach does not work that well in some cases. Say, the image was missing at some specific URL (maybe the server was down), the data is returned (for instance, it was an error page) and is cached. This data couldn't be converted to image (UIImage(data: data)), still, every next load invocation will have wrong cached data and won't try to check if there is a valid data present.

Maybe it makes sense to manage the same URLCache but manually using CachedURLResponse, instead of using .returnCacheDataElseLoad?

nalexn commented 4 years ago

Hey @NeverwinterMoon , Thanks for pointing out to this interesting edge case, I've implemented a fix.