title: How to cache ajax data with redux-observable - RxJS 5
body: <p>I'm trying to cache ajax data called via an a redux-observable epic.</p>
  
  <p>My goal is to call the API only the first time I dispatch <code>LOAD_DATA_REQUEST</code>, then the second time return the cached data.</p>
  
  <p>Below is the code I've tried, but the data is not cached, the API is being call whenever I dispatch <code>LOAD_DATA_REQUEST</code>.</p>
  
  <pre><code>const loadDataEpic =
          action$ =&gt; action$.ofType(LOAD_DATA_REQUEST)
              .mergeMap(action =&gt; getData$(action.criteria)
                  .map(x =&gt; loadDataSuccess(x.response))
                  .catch(error =&gt; Observable.of(loadDataFailure(error.xhr)))
              );
  
  const getData$ = criteria =&gt; Observable.ajax.post('some-url', criteria)
      .publishLast()
      .refCount();
  
  export default combineEpics(
      loadDataEpic 
  );
  </code></pre>
  
  <p>I also tried this:</p>
  
  <pre><code>const getData$ = criteria =&gt; Observable.ajax.post('some-url', criteria)
      .publishReplay(1)
      .refCount();
  </code></pre>
  
  <p>and</p>
  
  <pre><code>const getData$ = criteria =&gt; Observable.ajax.post('some-url', criteria)
      .shareReplay();
  </code></pre>