将NSCache内容保存到磁盘 [英] Save NSCache Contents to Disk

查看:260
本文介绍了将NSCache内容保存到磁盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个应用程序,需要保持一堆内存缓存的对象,但这不会失控,所以我打算使用NSCache来存储所有。看起来它会照顾清除,这对我来说是太棒了。

I'm writing an app that needs to keep an in-memory cache of a bunch of objects, but that doesn't get out of hand so I'm planning on using NSCache to store it all. Looks like it will take care of purging and such for me, which is fantastic.

我也想在启动之间保持缓存,所以我需要写缓存数据到磁盘。有一个简单的方法来保存NSCache内容到plist或什么?有没有更好的方法来完成这个使用非NSCache之外的东西?

I'd also like to persist the cache between launches, so I need to write the cache data to disk. Is there an easy way to save the NSCache contents to a plist or something? Are there perhaps better ways to accomplish this using something other than NSCache?

这个应用程序将在iPhone上,所以我只需要在iOS 4 +而不只是OS X。

This app will be on the iPhone, so I'll need only classes that are available in iOS 4+ and not just OS X.

谢谢!

推荐答案


我正在写一个应用程序,需要保持
一个
对象的内存缓存,但是没有得到
手,所以我计划使用NSCache
来存储它。看起来它会
照顾清除和这样的我,
这是太棒了。
我还希望在启动之间保持缓存
,所以我需要将
的缓存数据写入磁盘。有一个
简单的方法来保存NSCache内容
到plist或什么?有没有
或许更好的方法来完成这个
使用除NSCache之外的东西?

I'm writing an app that needs to keep an in-memory cache of a bunch of objects, but that doesn't get out of hand so I'm planning on using NSCache to store it all. Looks like it will take care of purging and such for me, which is fantastic. I'd also like to persist the cache between launches, so I need to write the cache data to disk. Is there an easy way to save the NSCache contents to a plist or something? Are there perhaps better ways to accomplish this using something other than NSCache?

正是CoreData的作用;

You pretty much just described exactly what CoreData does; persistency of object graphs with purging and pruning capabilities.

NSCache 不是用于辅助持久性。

NSCache is not designed to assist with persistency.

由于你建议坚持使用plist格式,所以使用Core Data并不是一个概念上的区别。

Given that you suggested persisting to a plist format, using Core Data instead isn't that big of a conceptual difference.

这篇关于将NSCache内容保存到磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆