0

I've implemented a simple RSS reader which shows title and date and also displays a thumbnail for each entry.

Now I want to implement caching in such a way that the last ten entries are saved on disk (including the images). I have little experience with Core Data and I'm wondering if it's the best solution for my problem.

Also, I'm relatively new to the MVC design pattern and I'd like to know what's the best way to design such a system. Right now my app has a RSSEntry class which stores title, date and thumbURL and represents the model. A class named RSSManager parses the feed and tells its delegate that it's finished parsing, providing an NSArray of RSSEntry instances. Then there's the view controller, a simple UITableViewController, which displays all this stuff in a tableview and also starts an asynchronous download using the imageURL from RSSEntry. When the download is finished, it asks the tableview to reload the respective rows so that the cell's activity indicator is stopped and the image is displayed.

Given this scenario, what's the best place to implement caching? I guess I need to save each image in the documents directory and then store the file's path, but I'm not sure what's the best way to design this. I want to avoid messy code and perhaps there's a known pattern to achieve this kind of stuff.

ySgPjx
  • 10,165
  • 7
  • 61
  • 78

1 Answers1

3

There was a similar question yesterday.

Anyway, for any network requests I'd use ASIHTTPRequest, plus they have cache support so you can use that to transparently cache your images. I'd probably write some sort of DownloadManager wrapper and call that from the view controller, much like you're using your RSSManager, and then use NSNotifications to have each (visible) row update itself as needed.

Community
  • 1
  • 1
André Morujão
  • 6,963
  • 6
  • 31
  • 41
  • +1 This is just great! I do use ASIHTTPRequest but I hadn't noticed this feature. This should also solve another problem I have, which is caching the actual web page of the article, right? I see there's a ASIWebPageRequest class, I guess it does what I need. – ySgPjx Apr 13 '11 at 19:02
  • I guess so, but I haven't actually tried ASIWebPageRequest. I only started using the cache class recently, and it's very nice, very easily customizable (e.g. when to perform a request or when to use a cached version, how long to cache for, etc). – André Morujão Apr 13 '11 at 19:05
  • So basically my problem would be solved, because my RSSEntry class already implements NSCoding and I could use archiving. If only I didn't want to learn Core Data so bad! */goes to do it with Core Data* – ySgPjx Apr 13 '11 at 19:14
  • lol imho it's definitely worth the effort of learning Core Data, despite the occasional headache :) (especially if you try using the magic NSFetchedResultsController class) I use it in most of my projects. When I started learning the iOS SDK, I was "lucky" enough to start doing persistence via Core Data. A friend of mine started with SQLite and on one of our projects I suggested he tried Core Data instead, and now he doesn't want anything else because of the amount of time it saves him, compared to doing "raw" SQLite. – André Morujão Apr 13 '11 at 19:35
  • I wasn't as lucky as you, but in relatively recent times I realized there's *a lot* of Apple tech to know about, so I'm currently reading a few books and rewriting a lot of code from scratch. – ySgPjx Apr 13 '11 at 19:39