如何禁用AFNetworking缓存 [英] How To Disable AFNetworking Cache

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

问题描述

是否可以禁用AFNetworking中的所有缓存功能?

Is it possible to disable all the cache features from AFNetworking?

我正在构建自己的自定义缓存系统,并且不希望这也占用磁盘空间。

I am building my own custom cache system and don't want this to take up disk space too.

谢谢,
Ashley

Thanks, Ashley

推荐答案

缓存是通过 NSURLCache 处理应用程序范围。如果未设置共享缓存,则不会缓存请求。即使使用共享的 NSURLCache ,iOS上的默认实现也不支持磁盘缓存。

Cacheing is handled application-wide by NSURLCache. If you don't set a shared cache, requests are not cached. Even with a shared NSURLCache, the default implementation on iOS does not support disk cacheing anyway.

这就是说,除非你有一个非常特别的理由来编写你自己的缓存系统,我会强烈推荐它。 NSURLCache 足以满足99.9%的应用程序:它处理来自传入响应的缓存指令并适当地使用新请求,并以不太可能的方式自动执行您的应用程序中的性能瓶颈。作为一个浪费了无数个小时自己制作一个人的人(以后因为完全没必要而扔掉它),我会说有更好的地方可以集中你的发展注意力。

That said, unless you have a very particular reason to write your own cacheing system, I would strongly recommend against it. NSURLCache is good enough for 99.9% of applications: it handles cache directives from incoming responses and uses them appropriately with new requests, and does so automatically in a way that is unlikely to be a performance bottleneck in your application. As someone who has wasted untold hours making one myself (and later throwing it away since it was completely unnecessary), I'd say that there are much better places to focus your development attention.

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

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