在我获得response
通过Alamofire后,在某些情况下,实现数据库或自己管理本地存储(文件等)可能有点矫枉过正.
我知道Alamofire requestCachePolicy
并且它已经缓存了响应(基于cache-control
s max-age
),但这更多地与减少请求数量/改善在线体验有关.
但是当我通过Alamofire没有连接时,是否可以使用缓存的响应? (Alamofire是否提供某种方便的方法来处理这个问题)
在iOS 7中,cachePolicy不起作用,它只是缓存下载的json.
//URLRequest
NSString *url = [NSString stringWithFormat:@"http://www.semhora.com/jsonparser/categories/categories_%d_test.json", _categoriesIndex];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLCacheStorageNotAllowed
timeoutInterval:60.0];
Run Code Online (Sandbox Code Playgroud)
如何在iOS 7中禁止缓存?