title: Best way to cache RESTful API results of GET calls
body: <p>I'm thinking about the best way to create a cache layer in front or as first layer for GET requests to my RESTful API (written in Ruby).</p>
  
  <p>Not every request can be cached, because even for some GET requests the API has to validate the requesting user / application. That means I need to configure which request is cacheable and how long each cached answer is valid. For a few cases I need a very short expiration time of e.g. 15s and below. And I should be able to let cache entries expire by the API application even if the expiration date is not reached yet.</p>
  
  <p>I already thought about many possible solutions, my two best ideas:</p>
  
  <ul>
  <li><p>first layer of the API (even before the routing), cache logic by myself (to have all configuration options in my hand), answers and expiration date stored to Memcached</p></li>
  <li><p>a webserver proxy (high configurable), perhaps something like Squid but I never used a proxy for a case like this before and I'm absolutely not sure about it</p></li>
  </ul>
  
  <p>I also thought about a cache solution like Varnish, I used Varnish for "usual" web applications and it's impressive but the configuration is kind of special. But I would use it if it's the fastest solution.</p>
  
  <p>An other thought was to cache to the Solr Index, which I'm already using in the data layer to not query the database for most requests.</p>
  
  <p>If someone has a hint or good sources to read about this topic, let me know.</p>