在ios中缓存数据的最佳选择

发布于 2024-12-01 00:29:01 字数 285 浏览 1 评论 0原文

我试图找到使用 ios 系统缓存多个字符串值的最佳选择。

到目前为止我发现的两个是 NSCache 和 NSDictionary,但是从我读到的内容来看,如果你的内存开始出现问题,NSCache 会转储数据,而且坦率地说,我不完全理解 NSDictionary。

所以我想知道是否还有其他选项可以满足我想要实现的目标..例如可能使用核心数据/本地 sqlite 等?基本上计划是从在线数据库获取信息,将一些更重要的信息存储在手机上,这些信息仅在数据库上的版本号(和整数)发生更改时才会更新,我将刷新缓存并更新它随着新的信息。

I am trying to find the best option for caching multiple string values with the ios system.

The two I have found so far are NSCache and NSDictionary however from what I have read NSCache will dump data if you start to have trouble with your memory and well quite frankly I dont fully understand NSDictionary.

So I am wondering what if any other options there are out there that will suite what I am trying to achive.. for instance maybe using core data / local sqlite etc? basically the plan is to get information from a online database, store some of the more important information on the phone that is only ever updated when the version number (and int) on the database has changed, the I will flush my cache and update it with the new information.

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

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

发布评论

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

评论(1

万劫不复 2024-12-08 00:29:01

如果我理解正确的话,似乎每次您的服务器上有新版本时,您都想下载新数据并将其中一些存储到设备上。

如果是这种情况,您可以将所有数据写入一个文件,并将其保存在手机上,然后稍后从该文件中重新加载所需的数据。我个人喜欢使用 NSCoding< /a> 为此,因为它可以让您轻松地将数据存储到文件中,然后在需要时将其读回。您甚至不需要一次读取所有数据,只需在何时读取您需要的数据,这可以帮助解决内存问题。您还可以使自己的自定义对象兼容 NSCoding,并且存储数据变得更加容易!

我建议尝试 NSCoding 。还有大量的教程可以帮助您解决问题。

另外, NSDictionaries 超级容易使用。您给它一个对象和一个key来存储它,当您想要返回对象时,只需提供NSDictionary< /code> key,然后您将取回该对象。

希望有帮助!

If I understand you correctly, it seems as though every time you have a new version on your server, you want to download the new data, and store some of it to the device.

If that's the case, you can write all the data to a file, and save it on the phone, and then reload the data that you need from that file later. I personally like using NSCoding for this, as it let's you store data easily to a file, and then read it back later when you need it. You don't even need to read all of the data at once, just what you need at what time, which can help with memory issues. You can also make your own custom objects NSCoding compliant, and it becomes even easier to store data!

I would suggest trying NSCoding out. There are also tons of tutorials out there to help you figure it out.

Also, NSDictionaries are super easy to use. You give it an object and a key to store it with, and when you want the object back, simply give the NSDictionary the key, and you'll get the object back.

Hope that Helps!

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