title: Caching for file server
body: <p>I have a java file server that serves file over http.  Each file is uniquely addressable by an ID like so:</p>
  
  <pre><code>http://fileserver/id/123455555
  </code></pre>
  
  <p>I am looking to add a caching layer to this so that the most frequently accessed files stay in memory.  I would also like to control the total size of the cache.  I am thinking to use ehcache or oscache for this, but I have only used them to cache serialized object before.  Would they be a good choice and are there any additional considerations for building a file cache?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Thanks for all the answers.  Some more details to about the file server to simplify (or complicate) the problem:</p>
  
  <ol>
  <li>Once a file is saved, it is never modified.</li>
  <li>MD5 hash to avoid duplicating files on save.  (I am
  aware of possible collision and security concerns)</li>
  <li>File server running on linux boxes.</li>
  </ol>
  
  <p><strong>Edit 2</strong>
  Though the server it self does not put any limitation on the file type it supports, Files are mostly images (jpg,gif, pgn), Word, excel, PDF no bigger than 10Mb.  </p>