title: Integrating persistent caching into Apache Httpclient with EhCache
body: <p>Today I wanted to integrate a persistent cache into apache's httpclient library. A quick look into the documentation for <a href="https://hc.apache.org/httpcomponents-client-ga/tutorial/html/caching.html" rel="nofollow">Http-Caching</a> tells you:</p>
  
  <blockquote>
    <p>The current release includes support for storing cache entries using EhCache and memcached implementations, which allow for spilling cache entries to disk or storing them in an external process.</p>
  </blockquote>
  
  <p>Fair enough, a quick google-search later I had exactly no idea what to do and how to do that ;)</p>
  
  <p>But there was one more hint: </p>
  
  <blockquote>
    <p>If none of those options are suitable for your application, it is possible to provide your own storage backend by implementing the HttpCacheStorage interface and then supplying that to caching HttpClient at construction time.</p>
  </blockquote>
  
  <p>So at least we know that the HttpCacheStorage needs to be initialized using some class that implements HttpCacheStorage. </p>
  
  <p>The question in a one liner: </p>
  
  <ul>
  <li>How do you integrate caching into any http-request? </li>
  <li>How do you initialiase an EhCache?</li>
  <li>How do your integrate an EhCache into the http-caching thingy.</li>
  </ul>