URLCache.shared.removeAllCachedResponses()
URLCache.shared.diskCapacity = 0
URLCache.shared.memoryCapacity = 0
if let cookies = HTTPCookieStorage.shared.cookies {
for cookie in cookies {
HTTPCookieStorage.shared.deleteCookie(cookie)
}
}
func clear(cache: Bool, cookies: Bool) {
if cache { clearCache() }
if cookies { clearCookies() }
}
fileprivate func clearCache() {
URLCache.shared.removeAllCachedResponses()
URLCache.shared.diskCapacity = 0
URLCache.shared.memoryCapacity = 0
}
fileprivate func clearCookies() {
let cookieStorage = HTTPCookieStorage.shared
guard let cookies = cookieStorage.cookies else { return }
for cookie in cookies {
cookieStorage.deleteCookie(cookie)
}
}
Không có nhận xét nào:
Đăng nhận xét