gpt4 book ai didi

objective-c - 如何在ios中将数据存储在NSCache中?

转载 作者:太空狗 更新时间:2023-10-30 03:36:14 25 4
gpt4 key购买 nike

我对 NSCache 很陌生。

我有一个 API 调用会产生多个对象。如何将这些对象存储在 NSCache 中,这样我就不需要再次调用 API。

NSCache 可以存储多少数据。NSCache 中存储数据是否有特定的限制。

请帮帮我。

最佳答案

看看documentationsample code .

An NSCache object is a collection-like container, or cache, that stores key-value pairs, similar to the NSDictionary class.

Here是 Nick Zitzmann 很好的解释。

NSCache is similar to NSMutableDictionary, with the differences being:
1. It is guaranteed to be thread-safe.
2. It is much slower to access.
3. It may throw out objects from time to time. You can set costs and limits, but they're not guaranteed to be followed.
4. It is not toll-free bridged to anything in CoreFoundation.
5. You can't query the number of objects that are in the cache.
6. You can't enumerate a cache.

I can only recommend using NSCache to store objects you wouldn't care about if they were arbitrarily destroyed. If the objects must not be destroyed, or if access speed is an issue, then use NSMutableDictionary instead.

关于objective-c - 如何在ios中将数据存储在NSCache中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12817476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com