Daily iOS
Networking

Image downloader and cache (request coalescing)

In a coding interview you're asked to build, in 30 minutes, an ImageManager that fetches an image by URL and returns it from cache if it's been fetched before. How would you handle several cells requesting the same URL at the same time?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

A manager wrapped in an actor looks up NSCache, then a dictionary of in-flight Tasks, then disk, then the network, and if the same URL is already downloading it waits on that Task instead of starting a new request, coalescing the requests.

Share a question