title: Android OkHttp how to handle ETag
body: <p>I'm try to do Android offline caching method using OkHttp. The flow is like this: </p>
  
  <ol>
  <li>I send an HTTP request with an ETag empty string at header field <code>if-none-catched</code> to the server, and the server returns a proper ETag. </li>
  <li>Then I store the ETag and cache the response.</li>
  <li>Next time when I fire the same service call I get the same ETag and set it to the HTTP request header and the server will return HTTP 304 if the ETag is the same.</li>
  </ol>
  
  <p>My issue now is how can I store and retrieve the ETag? Does OkHttp default will handle or I need store at SQLite? I keep looking on Google about OkHttp implement ETag sample code but all I get is just normal caching method. Link I refer:</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/7095897/im-trying-to-use-javas-httpurlconnection-to-do-a-conditional-get-but-i-neve">I&#39;m trying to use Java&#39;s HttpURLConnection to do a &quot;conditional get&quot;, but I never get a 304 status code</a></li>
  <li><a href="https://github.com/square/okhttp/wiki/Interceptors" rel="noreferrer">https://github.com/square/okhttp/wiki/Interceptors</a></li>
  <li><a href="https://stackoverflow.com/questions/25211333/correct-way-of-setting-up-cache-for-okhttp-in-android">Correct way of setting up cache for OkHttp in Android</a></li>
  <li><a href="https://gist.github.com/polbins/1c7f9303d2b7d169a3b1#file-restcontroller-java-L45" rel="noreferrer">https://gist.github.com/polbins/1c7f9303d2b7d169a3b1#file-restcontroller-java-L45</a></li>
  </ol>
  
  <p>so far what I achieved is only cache for 1st time service call, but never get latest data from server anymore. Appreciate if anyone can provide some guidance or found any good example of handle ETag and <code>if-none-catch</code> dynamically for OkHttp to share with. Any clarification feel free to ask.</p>