小智 32
// Flush all cached data
[[NSURLCache sharedURLCache] removeAllCachedResponses];
Run Code Online (Sandbox Code Playgroud)
Bir*_*chi 17
NSURLRequest* request = [NSURLRequest requestWithURL:fileURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0];
[webView loadRequest:request];
Run Code Online (Sandbox Code Playgroud)
(现在已修复拼写错误)
Tom*_*ift 11
我自己有这个问题,脚本和css文件被缓存.
我的解决方案是在src url上放置一个缓存清除参数:
<script src='myurl?t=1234'> ...
Run Code Online (Sandbox Code Playgroud)
其中t = 1234每次加载页面时都会更改.
jgo*_*zco 11
运用
[[NSURLCache sharedURLCache] removeAllCachedResponses];
Run Code Online (Sandbox Code Playgroud)
在进行调用之前或加载视图控制器时,这是一个静态函数,用于删除响应的所有缓存数据.只使用了cachePolicy,我没看到,我看到uiwebview可以刷新html文档,但不能刷新CSS,JS或图像等链接文档.
我尝试这个解决方案,它的确有效.
if (lastReq){
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:lastReq];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
}
lastReq=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:localUrl]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:10000];
[lastReq setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[self.mainWebView loadRequest:lastReq];
Run Code Online (Sandbox Code Playgroud)
- 首先,我删除了最后一个请求的缓存并调用删除所有其他缓存(我认为这不是那么重要) - 然后我创建一个nsurlrequest并忽略LocalCacheData - 最后,加载新请求
我检查它并重新加载所有文件(html,css,js和图像).
//to prevent internal caching of webpages in application
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];
sharedCache = nil;
Run Code Online (Sandbox Code Playgroud)
尝试使用这个.它将清除应用程序的url缓存内存.