0

I got a collectionView which displays 9 images (200x300px) at a time. The total number can go up to hundreds, though.

Currently I check in cellForItem if an Image is in the cache. If not, I'll load it from the file system and put it in the cache.

The problem: the first time I scroll through the collection it will drop frames because it is still loading the images from the file system. After one initial scroll-through it's butter smooth. (That's on a 5s)

I was wondering if it would be good practice to preload all (or the first x) the images in to the cache?

I don't see a big problem with the 5s but I fear it will crush older hardware.

Any thoughts?

1b0t
  • 432
  • 1
  • 5
  • 11

2 Answers2

2

Try to perform your disk loading mechanism in the background. You could set up a queue with NSOperationQueue filled with loading operations.

Using NSCache with preloading mechanisms does not make that much sense, since even if you preload all images, the system can and will evict the cache if it sees fit. In that case, the work you did with preloading was to no avail.

ff10
  • 3,046
  • 1
  • 32
  • 55
  • That sounds like a good Idea. I didn't realise that UIImage does synchronous loading of the Image. But It makes total sense. I'll try It! Thanks! – 1b0t Feb 14 '14 at 13:39
  • Happy to help. If you need to do some asynchronous web loading (instead of disk loading) in the future you might want to consider Mykola's answer. – ff10 Feb 14 '14 at 13:55
  • I've already implemented Async image loading/downscaling/saving myself. :) ... i'll take a look when I need it in my next project. – 1b0t Feb 14 '14 at 14:39
2

did you looked at SDWebImage? its already contain an asynchronous memory + disk image caching with automatic cache expiration handling

And also, I'm usually preload all images to avoid flickering

Mykola Denysyuk
  • 1,935
  • 1
  • 15
  • 15