我将缓存设置如下
var cacheSizeMemory = 20 * 1024 * 1024
var cacheSizeDisk = 100 * 1024 * 1024
var sharedCache = NSURLCache(memoryCapacity: cacheSizeMemory, diskCapacity: cacheSizeDisk, diskPath: "SOME_PATH")
NSURLCache.setSharedURLCache(sharedCache)
使用缓存策略创建请求
var request = NSMutableURLRequest(URL: NSURL(string: "\(baseUrl!)\(path)")!, cachePolicy: .ReturnCacheDataElseLoad, timeoutInterval: timeout)
提出请求并获得以下回复Cache-Control
private, max-age=60
然后尝试检查缓存
var cachedResponse = NSURLCache.sharedURLCache().cachedResponseForRequest(urlRequest)
值为零
有什么想法吗?