如何清除Cocoa中的WebView缓存? [英] How do you clear the WebView cache in Cocoa?
本文介绍了如何清除Cocoa中的WebView缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何清除/刷新 WebView 缓存在Cocoa应用程序中?
How do you clear/flush the WebView cache in a Cocoa app?
特别是,我想清除本地样式表的缓存。
In particular, I would like to clear the cache of a local stylesheet.
我试过下面的没有效果:
I have tried the following to no avail:
// Tried this before loadRequest
[[NSURLCache sharedURLCache] removeAllCachedResponses];
// Also tried this before and after loadRequest
[webView.mainFrame reloadFromOrigin];
甚至用新的替换 WebView
仍然使用缓存的样式表。
Even replacing the WebView
with a new one still uses the cached stylesheet.
推荐答案
其他建议的解决方案不适用于本地样式表资源)。
The other suggested solutions didn't work for the local stylesheet (though they should work for remote resources).
I finally managed to solve this via the resourceLoadDelegate, by explicitly setting the cache policy:
- (NSURLRequest *)webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)dataSource {
request = [NSURLRequest requestWithURL:[request URL] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:[request timeoutInterval]];
return request;
}
有趣的东西。
这篇关于如何清除Cocoa中的WebView缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文