Caching RSS entries with thumbnails using Core Data
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 开发者_JAVA百科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.
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 NSNotification
s to have each (visible) row update itself as needed.
精彩评论