从 Web 服务在 iOS 应用程序上存储动态数据的最佳方式

发布于 2024-11-28 20:05:06 字数 141 浏览 0 评论 0原文


我想知道通过网络服务在 iPhone 上存储数据的最佳方式是什么。 我希望将信息存储在设备上,这样人们就不需要每次需要时都访问网络服务。目前信息不多,不到150条记录。记录可能会不时更新,并且会添加一些新记录。存储数据的最佳方法是什么?

谢谢

I want to know what is the best way to store data on the iPhone from a web service.
I want the information to be stored on the device so the person doesn't need to access the web service every time he/she needs it. The currently information isn't much and contains less that 150 records. The records might update from time to time and a few new ones will be added. What is the best way to go about storing the data?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

写下不归期 2024-12-05 20:05:06

如果您使用 ASIHTTPRequest 来处理您的网络内容(如果您还没有这样做,我就无法唱歌它的赞誉足够高),你会发现它内置了一个缓存层,非常适合这种情况。

您可以通过简单的一行激活它;

[ASIHTTPRequest setDefaultCache:[ASIDownloadCache sharedCache]];

并且您可以完全控制缓存策略等 - 只需阅读文档即可。

当然,另一种简单的方法是 - 假设您的 Web 服务返回 JSON 或 XML - 只需根据请求参数的哈希值将响应存储在本地文件中,然后当您再次请求数据时,您可以先查看查看该文件是否存在,如果存在,请返回该数据,而不是返回网站。您也可以推出自己的缓存策略等。

自从我发现 ASIHTTPRequest 有一个缓存以来,我不需要再次推出自己的缓存。

我发现使用 coreData 或 sqllite3 对于我的 99% 的需求来说都太过分了,而且简单的缓存效果很好。

If you use ASIHTTPRequest for your network stuff (and if you don't already, I can't sing its praises highly enough), you will find it has a cache layer built in which is perfect for situations like this.

You can activate it with a simple one line;

[ASIHTTPRequest setDefaultCache:[ASIDownloadCache sharedCache]];

And you have full control over the cache policy etc - just read the documentation.

The other simple approach of course is - on the assumption that your web service is returning JSON or XML - simply to store the response in a local file against a hash of the request parameters, then when you request the data again, you can first look to see if the file exists and if it does, return that data rather than going back to the website. You can roll your own cache policies etc too.

Since I discovered ASIHTTPRequest had a cache though, I've not needed to roll my own again.

I find that using coreData or sqllite3 is just overkill for 99% my requirements and a simple cache works very well.

花开半夏魅人心 2024-12-05 20:05:06

如果数据是关系数据,Sqlite3 数据库将是您拥有的最佳存储选择。

此外,这还允许您从服务器检索并仅更新已更改的记录,从而节省时间和带宽。

从可扩展性的角度来看,这也是最好的选择,正如您所说的“当前信息不多”,因此给人的印象是这只是当前情况,可能会发生进一步的变化,可能会走向更多记录及时添加。

Sqite3 还为您提供了比使用 Core Data 等更多的控制和更好的性能。 这里有一篇文章解释了一些细节。此外,如果您使用 Objective-C 包装器,例如 FMDB,您无需管理即可获得所有优势你自己的复杂性。

If the data is relational, a Sqlite3 database would be the best storage option you have.

Also, this helps by allowing you to retrieve from the server and to update only the records that have changed, thus saving time and bandwidth.

This is the best option from a scalability point of view as well, as you stated that "current information isn't much", thus giving the impression that this is only a current situation, that may be subjected to further change, probably towards more records being added in time.

Sqite3 also gives you more control and better performance than using, for instance, Core Data. Here's an article explaining some of the details. Moreover, if you work through an Objective-C wrapper, such as FMDB, you get all the advantages without managing the complexity yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文