Search This Blog

Hiển thị các bài đăng có nhãn Cache. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Cache. Hiển thị tất cả bài đăng

Thứ Hai, 10 tháng 12, 2018

Xóa cache in ios

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)
    }
}

Thứ Năm, 31 tháng 8, 2017

Lưu trữ dưới cache in IOS

static func Sizefont_saveCache(size:Float){
        let defaults = UserDefaults.standard
        defaults.set(size, forKey: sizeFontKeyConstant)
    }
    
    static func Sizefont_readCache() -> Float{
        let defaults = UserDefaults.standard
        let size = defaults.float(forKey:sizeFontKeyConstant)
        if size != 0 {
            return size
        }
        return 0.5

    }