Why both Core Data and Cache?


The example code uses both type of persistence but I don’t understand why it doesn’t just use the Core Data without the cache? Is the cache faster?


What is happening here is that you are storing the images on the physical system drive and only storing the meta data about the photo in Core Data database. You could technically store the image data in Core Data as well, but it can bloat the database unnecessarily. Core Data is not really suited for storing large chunks of data such as the encoded image data. So Core Data is used to store all the information about the photo and it provides a mechanism for you to request the locally stored image through the ID. Does that make sense?


Yes that makes sense. Thank you.