使用 Core Data 缓存带有缩略图的 RSS 条目
我实现了一个简单的 RSS 阅读器,它显示标题和日期,还显示每个条目的缩略图。
现在我想以这样的方式实现缓存,将最后十个条目保存在磁盘上(包括图像)。我对核心数据的经验很少,我想知道这是否是解决我的问题的最佳解决方案。
另外,我对 MVC 设计模式比较陌生,我想知道设计这样一个系统的最佳方法是什么。现在我的应用程序有一个 RSSEntry
类,它存储 title
、date
和 thumbURL
并表示模型。名为 RSSManager
的类解析提要并告诉其委托它已完成解析,并提供 NSArray
的 RSSEntry
实例。然后是视图控制器,一个简单的 UITableViewController
,它在表格视图中显示所有这些内容,并使用 RSSEntry
中的 imageURL
启动异步下载。下载完成后,它会要求表格视图重新加载相应的行,以便单元格的活动指示器停止并显示图像。
考虑到这种情况,实施缓存的最佳位置是什么?我想我需要将每个图像保存在文档目录中,然后存储文件的路径,但我不确定设计这个的最佳方法是什么。我想避免混乱的代码,也许有一个已知的模式可以实现这种东西。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
昨天有一个类似问题。
不管怎样,对于任何网络请求,我都会使用 ASIHTTPRequest,而且它们还有 缓存支持,以便您可以使用它来透明地缓存您的图像。我可能会编写某种
DownloadManager
包装器并从视图控制器调用它,就像您使用RSSManager
一样,然后使用NSNotification
code>s 让每个(可见)行根据需要更新自身。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 yourRSSManager
, and then useNSNotification
s to have each (visible) row update itself as needed.