Moya: Question: Moya not respecting SessionManager configuration for requests?

Created on 30 Sep 2016  路  5Comments  路  Source: Moya/Moya

Hi all,

I'm currently trying to implement a cache solution with a custom URLCache (and modify some cache methods like in this example (http://stackoverflow.com/a/19847811), Moya/Alamofire and therefore I'm using a custom SessionManager with my provider which configures the URLCache to use.

Especially this part is interesting:

// ...
URLCache.shared = myCustomURLCache
sessionConfig.urlCache = URLCache.shared
sessionConfig.requestCachePolicy = .returnCacheDataElseLoad
// ...

I pass the final manager to my MoyaProvider, but it seems, that the send request does not have the correct RequestCachePolicy set.

Now if I put some output in
func sendRequest(_ target: Target, request: URLRequest, queue: DispatchQueue?, progress: Moya.ProgressBlock?, completion: @escaping Moya.Completion) -> CancellableToken {

I'm seeing this:

print(manager.session.configuration.requestCachePolicy.rawValue) // correctly set
print(request.cachePolicy.rawValue) // wrong (always `useProtocol...`)
let alamoRequest = manager.request(request as URLRequestConvertible)
print(alamoRequest.request?.cachePolicy.rawValue) // wrong

I don't know if this is intended or maybe a bug in Alamofire as Moya is using the correctly configured manager to build the alamoRequest.

Is this behavior intended in any way?

bug? question

Most helpful comment

Yes, I will do that tomorrow. I tested it and it works well :)

All 5 comments

Also have this problem. I tried to set custom SessionManager with RequestRetrier that was introduced in Alamofire 4, but implementation of RequestRetrier protocol not invokes.

_Edit: moved my comment in a new issue_
I opened a new issue concerning the request retrier, and will try to do a pull request with this functionality.
Of course you can still try and use this reference https://github.com/Moya/Moya/blob/master/docs/Examples/SubclassingProvider.md, but It would cause less surprise, if the Alamofire's requestRetrier worked transparently.

This seems like a great addition! Would you be able to submit a PR implementing this, @jeryRazakarison?

Yes, I will do that tomorrow. I tested it and it works well :)

Closed by #767, thanks @jeryRazakarison!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PlutusCat picture PlutusCat  路  3Comments

hamada147 picture hamada147  路  3Comments

hjzCy picture hjzCy  路  3Comments

dimpiax picture dimpiax  路  3Comments

pedrovereza picture pedrovereza  路  3Comments