AF网络和缓存 [英] AFNetworking and caching

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

问题描述

我正在下载要缓存的WMS切片。我正在使用包含NSURLCache的AFNetworking。来自服务器的响应在标头中不包含Cache-Control协议。

I am downloading WMS tiles which I want to cache. I'm using AFNetworking which includes NSURLCache. The responses from the server do not contain Cache-Control protocols in the header.

我向服务器人员询问了这一点,并且不熟悉服务器端的缓存控制。此刻,他忙于其他工作。我是否需要他实现缓存控制,还是可以强制NSURLCache在不包含响应头的信息的情况下对其进行缓存?

I asked the server guy about this and was unfamiliar with server side cache-control. At the moment, he is swamped with other work. Do I need him to implement the cache-control or can I force NSURLCache to cache them w/out the info the response header?

NSURLCache是​​否持久?如果是这样,如何清除缓存?磁贴将需要在每个会话中检索,并且不能持久。

Is NSURLCache persistent? If so, how can I clear the cache? The tiles will need to be retrieved per session and can not be persistent.

还是应该创建自己的缓存?

Or should I create my own cache?

推荐答案

当您激活NSURLCache时,它将适用于基于NSUrlRequest的任何请求(例如AFNetworking)。激活NSURLCache后,您可以指定其最大大小。您还可以通过调用removeAllCachedResponses或removeCachedResponsesForRequest方法来清除缓存。如果服务器未发送任何缓存控制信息,则缓存仍将缓存文件。如果要完全控制缓存,则可以创建自己的缓存。如果您想查看其示例代码,请查看 https://github.com/evermeer/ EVURLCache

When you activate NSURLCache it will work for any request that is based on the NSUrlRequest (like AFNetworking). The moment you activate the NSURLCache you can specify it's maximum size. You can also clear the cache by calling the removeAllCachedResponses or removeCachedResponsesForRequest methods. If the server does not send any cache control information, then the cache will still cache the file. If you want complete control over the cache, you could create your own cache. If you would like to see a sample code for that, then have a look at https://github.com/evermeer/EVURLCache

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

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