What is the best way to cache tweets – text, image, etc. – so they can be displayed right away when a user launches an app while new ones are fetched for in the background? It sounds like NSCachesDirectory is the best way since this is not backed up and if it is cleared the data can just be re-downloaded. I’m just curious if the best way is to create a “Tweet” class and create instances of this class and store them in the cache each time new ones are downloaded or if there is another recommended way?
Share
NSCachesDirectoryis just/Library/Cachesfolder of your app sandbox. It appears to be a system managed folder. The last time I checked, it’s used by several APIs to keep caches of downloaded files from the Internet (CFURL related APIs). You can use it though. But I wouldn’t keep tweets and images directly as files in this folder.Depending on the purpose of your app, the common approach to cache downloaded content is still to use a database. You can choose to use sqlite3 API directly, or CoreData which is built on top of sqlite3. I imagine most apps calls sqlite3 directly because CoreData is not that clear and bulletproof on the Mac OS X platform historically. It’s designed so that you wouldn’t need knowledge of SQL to start development. If you did know something about SQL, you’ll find it lacking of certain features.