NSURLCache 使用什么缓存算法?
Apple 的 NSURLCache
类具有 不错的文档,但它没有说明它使用的缓存算法。是 LRU、LFU 还是完全别的什么?
我正在为 iPad 进行开发,希望通过使用 [NSURLCache setDiskCapacity]
来利用 NSURLCache
的磁盘缓存功能来缓存照片(默认值似乎是为 0)。这个值的上限是多少?
Apple's NSURLCache
class has decent documentation, but it doesn't say what caching algorithm it uses. Is it LRU, LFU, or something else entirely?
I'm developing for the iPad, and am hoping to make use of NSURLCache
's disk-caching abilities to cache photos, by using [NSURLCache setDiskCapacity]
(the default seems to be 0). What's the upper limit on this value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
磁盘容量的上限似乎是设备的磁盘容量。我看不到任何有关“软件强加”限制的信息。
至于缓存算法,似乎没有任何苹果提供的文档,但我确实找到了 这个。严格来说,这并不是您所要求的,但它确实可以让您深入了解正在发生的事情。我相信这个算法使用的是多队列缓存算法(?),它按大小排序,然后按最近最少使用排序。
如果您正在做一些依赖于了解缓存算法的事情,您可以用它来做一些事情。
The upper limit on the disk capacity seems to be the disk capacity of the device. I can't see anything about a 'software imposed' limit.
As for the caching algorithm, there doesn't seem to be any apple provided documentation but I did find this. It's not strictly what you asked for, but it certainly gives you an insight into what's going on. I believe this one to be using a Multi Queue Caching Algorithm (?) where it's sorted by size and then by least recently used.
If you were making something dependant on knowing the caching algorithm, you could do some thing with this.
我猜你将不得不编写一些测试用例来解决这个问题。 (当然,请注意,参数可能会随着 iOs 版本、硬件平台等的变化而变化。)
I would guess that you're going to have to write some test cases to figure it out. (And, of course, be aware that the parameters may change with iOs version, hardware platform, etc.)