NSURLConnection Cache Problem

December 17, 2016

NSURLConnection Cache Problem

Some of us might be forced to use NSURLConnection (I doubt that anyone is still using it willingly) and the problem of constantly growing amount of data an app persists on disc might be not new. I had this problem in an app and I couldn't figure out at first what is going on. After a bit of debuggin I got down to the issue.

<!--more-->

It turns out that NSURLConnection caches data by default. However Apple gives us some tools to control caching process through NSURLRequest's cachePolicy parameter when you instantiate it.
The thing is that the project still uses AFNetworking v.2.6.3 and to switch to the v.3 means a lot of refactoring, possible bugs, fixes for those possible bugs and so on. It means that we are pretty much stuck with this version until we have time to update this library.

In search of the caching origins

By using AFNetworking we decided to include it's UIKit extensions, which give you some neat methods to ease your networking calls for them. We've been extensively using UIImageView extensions. I thought that this was the reason and started to dig deeper

Comments

comments powered by Disqus