清除NSURLSession缓存 [英] Clear NSURLSession Cache

查看:394
本文介绍了清除NSURLSession缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NSURLSession 使用 dataTaskWithRequest执行HTTP发布 NSMutableURLRequest :completionHandler:方法。当我第一次执行请求时,事情需要花费相当长的时间才能完成,并在完成处理程序中显示一些反馈。下次再次发出同一请求时,它几乎立即发生,并且之间的时间很少,这使我相信系统正在缓存此数据任务的内容。

I'm using NSURLSession to perform an HTTP Post NSMutableURLRequest, using the dataTaskWithRequest:completionHandler: method. When I perform a request for the first time, things take a reasonable amount of time to complete and show some feedback in the completion handler. On the next time that same request is fired, it happens almost instantaneously with very little time in between, which leads me to believe that the system is caching the contents of this data task.

因为我不需要查看返回的数据,所以NSURLSession是执行此操作的最佳方法吗?它需要与NSURLSession做到的WatchKit一起很好地工作,这就是为什么我首先选择它。我最好希望找到一种方法,在每次请求后才清除缓存。如果需要,我可以切换到NSURLConnection,但这是最好的。谢谢!

As I don't need to view the returned data, is NSURLSession the best way to do this? It needs to work well with WatchKit, which NSURLSession does, which is why I chose it in the fist place. I would preferably like to find a way to just clear the cache after each request. If need be, I could switch to NSURLConnection, but this would be best. Thanks!

推荐答案

星历模式将不使用任何缓存。

Ephemeral mode will not use any cache.

NSURLSessionConfiguration *ephemeralConfigObject = [NSURLSessionConfiguration ephemeralSessionConfiguration];

这篇关于清除NSURLSession缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆