title: Caching network calls using RxJava for some duration
body: <p>I am making a network using <code>Retorfit</code> + <code>RxJava2</code> and I want to cache the response for 30 seconds. Any calls made after 30 seconds interval should get the latest results from server. I tried doing this using <code>Replay</code> operator but it still makes a network call every time I call subscribe. I am not an expert in RxJava so maybe my understanding of using <code>Replay</code> for caching like that is wrong.</p>
  
  <pre><code>public Observable&lt;Name&gt; getName() {
          return retrofitBuilder.getName()
                  .subscribeOn(Schedulers.io())
                  .replay(30, TimeUnit.SECONDS,Schedulers.io())
                  .autoConnect();
      }
  </code></pre>
  
  <p>and I am calling the above code like this:</p>
  
  <pre><code> service.getName()
          .subscribe(new Consumer&lt;Name&gt;()
              {
                  @Override
                  public void accept(Name name) throws Exception
                  {
                      Log.d("getName", "Name: " + name.toString());
                  }
              }
              , new Consumer&lt;Throwable&gt;()
              {
                  @Override
                  public void accept(Throwable throwable) throws Exception
                  {
                      Log.d("getName", throwable.getMessage());
                  }
              });
  </code></pre>
  
  <p><strong>UPDATE:</strong> My apology if I didn't explain my question clearly. What I want is caching on a particular request instead of caching it on <code>HttpClient</code> level which applies the caching strategy to all the request being made through it. In the end I would like to define different caching expiration for different request when needed. Not all my request needs caching for small duration. I was wondering if I could do just that.</p>
  
  <p>Appreciate your help in this. </p>