Save NSCache Contents to Disk

前端 未结 4 1934
不知归路
不知归路 2020-12-10 02:59

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 l

4条回答
  •  温柔的废话
    2020-12-10 03:19

    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?

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

    NSCache is not designed to assist with persistency.

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

提交回复
热议问题