Fail to retrieve cached data when offline
See original GitHub issueSteps to reproduce
- Do get request when online
- Validate data cached using
adb shell
- Kill the app
- Disable
Cellular data
andWifi
- Running the app
Server response while online
2-22 22:53:56.735 15941-16350/com.mycompany.android D/Retrofit: <--- HTTP 200 http://mycompany.com/api/test (638ms)
12-22 22:53:56.735 15941-16350/com.mycompany.android D/Retrofit: Server: nginx/1.4.6 (Ubuntu)
12-22 22:53:56.735 15941-16350/com.mycompany.android D/Retrofit: Content-Type: application/json
12-22 22:53:56.735 15941-16350/com.mycompany.android D/Retrofit: Transfer-Encoding: chunked
12-22 22:53:56.735 15941-16350/com.mycompany.android D/Retrofit: Connection: keep-alive
12-22 22:53:56.735 15941-16350/com.mycompany.android D/Retrofit: Cache-Control: max-age=900, max-stale=4838400, public
12-22 22:53:56.735 15941-16350/com.mycompany.android D/Retrofit: Allow: POST, GET, DELETE
12-22 22:53:56.735 15941-16350/com.mycompany.android D/Retrofit: Date: Tue, 22 Dec 2015 20:54:03 GMT
12-22 22:53:56.735 15941-16350/com.mycompany.android D/Retrofit: OkHttp-Selected-Protocol: http/1.1
12-22 22:53:56.735 15941-16350/com.mycompany.android D/Retrofit: OkHttp-Sent-Millis: 1450817636439
12-22 22:53:56.735 15941-16350/com.mycompany.android D/Retrofit: OkHttp-Received-Millis: 1450817636733
12-22 22:53:56.742 15941-16350/com.mycompany.android D/Retrofit: [‘my data’]
12-22 22:53:56.742 15941-16350/com.mycompany.android D/Retrofit: <--- END HTTP (3180-byte body)
Logs when offline
12-22 22:58:15.980 20271-20271/com.mycompany.android W/System.err: com.mycompany.api.MyException: Unable to resolve host "mycompany.com": No address associated with hostname
12-22 22:58:15.980 20271-20271/com.mycompany.android W/System.err: at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:395)
12-22 22:58:15.981 20271-20271/com.mycompany.android W/System.err: at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
12-22 22:58:15.981 20271-20271/com.mycompany.android W/System.err: at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
12-22 22:58:15.981 20271-20271/com.mycompany.android W/System.err: at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
12-22 22:58:15.981 20271-20271/com.mycompany.android W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-22 22:58:15.981 20271-20271/com.mycompany.android W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-22 22:58:15.981 20271-20271/com.mycompany.android W/System.err: at retrofit.Platform$Android$2$1.run(Platform.java:142)
12-22 22:58:15.981 20271-20271/com.mycompany.android W/System.err: at java.lang.Thread.run(Thread.java:818)
12-22 22:58:16.343 20271-20358/com.mycompany.android D/Retrofit: ---> HTTP GET http://mycompany.com/api/test
12-22 22:58:16.343 20271-20358/com.mycompany.android D/Retrofit: ---> END HTTP (no body)
12-22 22:58:16.346 20271-20358/com.mycompany.android D/Retrofit: ---- ERROR http://mycompany.com/api/test
12-22 22:58:16.347 20271-20358/com.mycompany.android D/Retrofit: java.net.UnknownHostException: Unable to resolve host "mycompany.com": No address associated with hostname
at java.net.InetAddress.lookupHostByName(InetAddress.java:427)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
at java.net.InetAddress.getAllByName(InetAddress.java:215)
at com.squareup.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)
at com.squareup.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:188)
at com.squareup.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:157)
at com.squareup.okhttp.internal.http.RouteSelector.next(RouteSelector.java:100)
at com.squareup.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:357)
at com.squareup.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:340)
at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)
at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
at com.squareup.okhttp.Call.getResponse(Call.java:273)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201)
at com.squareup.okhttp.Call.execute(Call.java:81)
at retrofit.client.OkClient.execute(OkClient.java:53)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:818)
12-22 22:58:16.347 20271-20358/com.mycompany.android D/Retrofit: ---- END ERROR
12-22 22:58:16.372 20271-20363/com.mycompany.android I/OpenGLRenderer: Initialized EGL, version 1.4
12-22 22:58:16.378 20271-20363/com.mycompany.android D/OpenGLRenderer: Enabling debug mode 0
12-22 22:58:16.407 20271-20271/com.mycompany.android D/com.instabug.library: ActivityLifecycleListener: SplashActivity_ paused
12-22 22:58:16.407 20271-20271/com.mycompany.android D/com.instabug.library: Stopping shake detection
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: retrofit.RetrofitError: Unable to resolve host "mycompany.com": No address associated with hostname
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:395)
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at retrofit.Platform$Android$2$1.run(Platform.java:142)
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at java.lang.Thread.run(Thread.java:818)
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: Caused by: java.net.UnknownHostException: Unable to resolve host "mycompany.com": No address associated with hostname
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at java.net.InetAddress.lookupHostByName(InetAddress.java:427)
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at java.net.InetAddress.getAllByName(InetAddress.java:215)
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at com.squareup.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at com.squareup.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:188)
12-22 22:58:16.429 20271-20271/com.mycompany.android W/System.err: at com.squareup.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:157)
12-22 22:58:16.430 20271-20271/com.mycompany.android W/System.err: at com.squareup.okhttp.internal.http.RouteSelector.next(RouteSelector.java:100)
12-22 22:58:16.430 20271-20271/com.mycompany.android W/System.err: at com.squareup.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:357)
12-22 22:58:16.430 20271-20271/com.mycompany.android W/System.err: at com.squareup.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:340)
12-22 22:58:16.430 20271-20271/com.mycompany.android W/System.err: at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)
12-22 22:58:16.430 20271-20271/com.mycompany.android W/System.err: at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
12-22 22:58:16.430 20271-20271/com.mycompany.android W/System.err: at com.squareup.okhttp.Call.getResponse(Call.java:273)
12-22 22:58:16.430 20271-20271/com.mycompany.android W/System.err: at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230)
12-22 22:58:16.430 20271-20271/com.mycompany.android W/System.err: at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201)
12-22 22:58:16.430 20271-20271/com.mycompany.android W/System.err: at com.squareup.okhttp.Call.execute(Call.java:81)
12-22 22:58:16.430 20271-20271/com.mycompany.android W/System.err: at retrofit.client.OkClient.execute(OkClient.java:53)
12-22 22:58:16.430 20271-20271/com.mycompany.android W/System.err: at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
12-22 22:58:16.430 20271-20271/com.mycompany.android W/System.err: ... 7 more
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
What's a valid fallback when caching fails in offline web app?
There is no fallback. Your page will work as normal, but no part of it will not be inserted into the Appcache if...
Read more >cached data, offline capabilities - Power Platform Community
Solved: Hi, I have built an app to mostly work offline during the data, and then in the evening when I am connected,...
Read more >KB225414: When a document is used as a home screen ...
KB225414: When a document is used as a home screen, using a new feature “Clear Cached Data” in offline mode that is available...
Read more >How Do I Fix My Caching Problems Or Clear Web Browser's ...
Once your browser and go to Tools > History and click Clear browsing data. 15. In the next window select Cached images and...
Read more >Access data offline | Firestore - Firebase
If you get a document while the device is offline, Cloud Firestore returns data from the cache. When querying a collection, an empty...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
test
andtest/
are different URLs. No bug!I use the interceptor like below and works fine for me. Hope it will help you
private val offlineResponseCacheInterceptor = Interceptor { chain -> val originalResponse = chain.proceed(chain.request()) originalResponse.newBuilder() .removeHeader(“Pragma”) .header(“Cache-Control”, String.format(“max-age=%d”, 60)) .build() }