-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return cached response when without network? #713
Comments
Hey there, great question! First, to return empty data you can The data you return should be a response representative of what your API actually returns. For example, if you request a The reason it's not optional is to force developers to specify something so it's easier to unit test the code that uses Moya. Network call stubs are first-class citizens in Moya, and are as foundational to the library. I understand that not every developer agrees, so I hope this clarifies things to your satisfaction. We're always looking for ways to improve our documentation, do you have any suggestions where we could add this explanation to help future developers? |
After your comment, i tried to read source code of endpointClosure: @escaping EndpointClosure = MoyaProvider.DefaultEndpointMapping And Endpoint(URL: url, sampleResponseClosure: {.networkResponse(200, target.sampleData)}, method: target.method, parameters: target.parameters) I think: It's simple for developer to use |
Ah, you're looking to stub requests locally, to return previous requests? Interesting. I'll have to think about that. Having a plugin to record network calls might be cool, too, especially for testing. |
Return cached response when without network. Also as you say. Let's talking about it. |
Return previous requests is better, but is that the things Moya should do? I think it's the data-model's job. And we should not confuse the data-model with the service-model. this is my opinion... |
I agree with @DeepMissea. This should be it's own library, caching is really hard Plug for a talk my friend gave: https://www.youtube.com/watch?v=8uqXuEZLyUU Caching would be a level above Moya though |
Nooooo, i recommand use this: typedef NS_ENUM(NSUInteger, NSURLRequestCachePolicy)
{
NSURLRequestUseProtocolCachePolicy = 0,
NSURLRequestReloadIgnoringLocalCacheData = 1,
NSURLRequestReloadIgnoringLocalAndRemoteCacheData = 4, // Unimplemented
NSURLRequestReloadIgnoringCacheData = NSURLRequestReloadIgnoringLocalCacheData,
NSURLRequestReturnCacheDataElseLoad = 2,
NSURLRequestReturnCacheDataDontLoad = 3,
NSURLRequestReloadRevalidatingCacheData = 5, // Unimplemented
}; With header fields like ------Edit------- I think, request cache-control is useful. |
@wilddylan can you elaborate? |
@wilddylan I'm going to close this for now, please do re-open if you'd like to further explore adding a cache! |
Using: 8.0.0-beta2
Hi, When i want to use
Moya
, i find that:What should i return when my request without sampleData?
Why not change sampleData to optional?
The text was updated successfully, but these errors were encountered: