gpt4 book ai didi

ios - 如何使用图像的缓存目录

转载 作者:行者123 更新时间:2023-11-28 21:29:10 30 4
gpt4 key购买 nike

我在 tableview 中显示图片。我希望如果图像已下载则不要再次下载。如何使用缓存目录实现此方案。

最佳答案

看看 NSCache,它像一个可变字典一样工作,但它是线程安全的。

NSCache objects differ from other mutable collections in a few ways:

The NSCache class incorporates various auto-removal policies, which ensure that it does not use too much of the system’s memory. The system automatically carries out these policies if memory is needed by other applications. When invoked, these policies remove some items from the cache, minimizing its memory footprint.

You can add, remove, and query items in the cache from different threads without having to lock the cache yourself.

Unlike an NSMutableDictionary object, a cache does not copy the key objects that are put into it.

These features are necessary for the NSCache class, as the cache may decide to automatically mutate itself asynchronously behind the scenes if it is called to free up memory.

您可以使用图片的 URL 和图片本身作为值来为图片设置关键字。
Documentation .
NSHipster发布。

关于ios - 如何使用图像的缓存目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36858270/

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