title: RxJava and Cached Data
body: <p>I'm still fairly new to RxJava and I'm using it in an Android application. I've read a metric ton on the subject but still feel like I'm missing something.</p>
  
  <p>I have the following scenario: </p>
  
  <p>I have data stored in the system which is accessed via various service connections (AIDL) and I need to retrieve data from this system (1-n number of async calls can happen). Rx has helped me a ton in simplifying this code. However, this entire process tends to take a few seconds (upwards of 5 seconds+) therefore I need to cache this data to speed up the native app. </p>
  
  <p>The requirements at this point are: </p>
  
  <ol>
  <li><p>Initial subscription, the cache will be empty, therefore we have to wait the required time to load. No big deal. After that the data should be cached. </p></li>
  <li><p>Subsequent loads should pull the data from cache, but then the data should be reloaded and the disk cache should be behind the scenes. </p></li>
  </ol>
  
  <p>The Problem: I have two Observables - A and B. A contains the nested Observables that pull data from the local services (tons going on here). B is much simpler. B simply contains the code to pull the data from disk cache. </p>
  
  <p>Need to solve: 
  a) Return a cached item (if cached) and continue to re-load the disk cache.
  b) Cache is empty, load the data from system, cache it and return it. Subsequent calls go back to "a". </p>
  
  <p>I've had a few folks recommend a few operations such as flatmap, merge and even subjects but for some reason I'm having trouble connecting the dots. </p>
  
  <p>How can I do this? </p>