evermeer / EVURLCache

a NSURLCache subclass for handling all web requests that use NSURLRequest
Other
297 stars 49 forks source link

POST request seems to be unable to be recreated from cache #34

Closed nmDejamobile closed 7 years ago

nmDejamobile commented 7 years ago

On the same request, when being in plane mode, if I call it using .GET method, cache is returned but when I call it using .POST, no cache is returned. Cache data is well loaded in EVURLCache.swift cachedResponseForRequest function but not forwarder to Alamofire (I didn't try without Alamofire, do perhaps this is non only on EVURLCache side).

So as I only need cache when in plane mode, I did a workaround by using .GET method when no network is detected. As I don't make a server call, it works (otherwise my server checks the calling method and refuse non POST methods). But this is a very ugly workaround I did IMO, and it would be nice to have cache returned for POST.

This also works as the cache storage makes no difference for a GET or a POST, this is the same folder. I also think this should be fixed by having different cache folders depending on request method.

evermeer commented 7 years ago

Sorry, but post requests will not be cached.

For an explanation see: http://stackoverflow.com/questions/33871151/post-request-using-nsurlsession-cache-response

So if you do want to cache your post request, then you have to implement that yourself (maybe as an alamofire request extension?)

nmDejamobile commented 7 years ago

Ok, but the fact is that the lib caches the POST response. It just refuses to give it back when offline. But ok, I'll keep my workaround and think of another way to do next time.

evermeer commented 7 years ago

If it does do the save (which is still strange), then you could use the fail handler from the post to get the file from disk. You can use the EVReflection.storagePathForRequest function to get the correct url