first loop for caching images according to list