iOS开发

WKWebView清除缓存

2018-07-02  本文已影响35人  HeavenWong

一. UIWebView清楚缓存

  1. NSURLCache 和 NSHTTPCookieStorage 对象的清除方式
 NSHTTPCookie *cookie;
    NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    for (cookie in [storage cookies]) {
        [storage deleteCookie:cookie];
    }
    NSURLCache *cache = [NSURLCache sharedURLCache];
    [cache removeAllCachedResponses];
    [cache setMemoryCapacity:0];
    [cache setDiskCapacity:0];

  1. NSURLRequest对象的不缓存机制:NSURLRequestReloadIgnoringCacheData

//NSURLRequest *urlRequest = [NSURLRequest requestWithURL:_url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15.0];
//[self.web_view loadRequest:urlRequest];
[self.web_view loadRequest:[NSURLRequest requestWithURL:_url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0]];

二. WKWebView清除缓存

[self.web_view loadRequest:[NSURLRequest requestWithURL:_url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0]];
上一篇 下一篇

猜你喜欢

热点阅读