gpt4 book ai didi

iphone - UIWebView 并不总是调用 -[NSURLCache storeCachedResponse :forRequest:]

转载 作者:技术小花猫 更新时间:2023-10-29 11:12:37 24 4
gpt4 key购买 nike

UIWebView 似乎并不总是在加载资源时调用 storeCachedResponse:forRequest:。有谁知道为什么?我正在尝试使用 -[NSURLCache storeCachedResponse:forRequest:] 来缓存图像,它可以很好地完成大部分工作,但在某些情况下 UIWebView 不会调用此方法在实际有图像的页面加载上。

最佳答案

回答赏金提供者的查询:

I'm seeing this for small files (100s of bytes) as well. The webview also fails to call cachedResponseForRequest:

我找到了 this question直接解决此行为:

Despite Apple's documentation indicating otherwise, NSURLCache on iOS doesn't do any disk (flash) caching at all. You can subclass NSURLCache to change the behaviour of the fetch and store operations to use the disk (like SDURLCache does), but due to the following severe limitations of how the cache is used and implemented, this doesn't work as well as you'd expect:

  • NSURLConnection doesn't even call storeCachedResponse:forRequest: for files over about 50KB (>= 52428 bytes, to be exact). This makes subclassing NSURLCache pointless for our use (200KB images), because it won't even get to the cache. As a result, we have to add caching manually at a level above NSURLConnection.

  • Even when one calls the NSURLCache's built-in storeCachedResponse:forRequest: manually, it only stores the response in memory if it's less than about 180KB. I tested this by calling storeCachedResponse manually and seeing that the before/after currentMemoryUsage didn't change for data lengths above about 180KB. So we have to write our own LRU memory caching too.

(强调我的。)

这似乎是引起行为的原因。作为the current accepted answer points out , ASIHTTPRequest是此行为的预期解决方法。

但是,请注意页面顶部的警告:

Please note that I am no longer working on this library - you may want to consider using something else for new projects. :)

您应该考虑依赖受支持的库,或者,如果您愿意,一旦它成为您的代码的基础,就回馈给这个库。

关于iphone - UIWebView 并不总是调用 -[NSURLCache storeCachedResponse :forRequest:],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9039144/

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