title: RxJava Android return cache before network
body: <p>I am trying to achieve a cache observable returning quickly, then a network request updating the UI once it completes.</p>
  
  <p>Using Rx startWith, works fine if the phone is in signal, however if I put phone in Aeroplane mode, the retrofit web call fails onError so quickly, that my cache value returned from startWith never gets returned, as onError terminates the observable immediately.  I also need to know if onError is thrown by the observable for showing to the user.  My cache is almost instant, so I would prefer to return the cache before any network call is attempted. Is there a way to do this neatly? or a better way to do this?</p>
  
  <pre><code>public Observable&lt;String&gt; getMyString(String key){
          WebRequestDbEntity myCachedString = mCache.getWebRequest(key);
          String cachedString = myCachedString.getValue();
  
          return retrofitWebDataStore().getMyString(key)
                  .startWith(Observable.just(cachedString))
                  .map(networkString -&gt; {
                      mCache.saveRequest(key, networkString);
                      return networkString;
                  });
      }
  </code></pre>
  
  <p>In the presentation layer:</p>
  
  <pre><code>        getMyString(key)
                      .subscribeOn(Schedulers.io())
                      .observeOn(AndroidSchedulers.mainThread())
                      .subscribe(this::onSuccess, this::onError);
  </code></pre>