Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caching for file server

Tags:

java

file

caching

I have a java file server that serves file over http. Each file is uniquely addressable by an ID like so:

http://fileserver/id/123455555

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?

Edit

Thanks for all the answers. Some more details to about the file server to simplify (or complicate) the problem:

  1. Once a file is saved, it is never modified.
  2. MD5 hash to avoid duplicating files on save. (I am aware of possible collision and security concerns)
  3. File server running on linux boxes.

Edit 2 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.

like image 690
ltfishie Avatar asked Apr 21 '26 09:04

ltfishie


1 Answers

guava cache? http://code.google.com/p/guava-libraries/wiki/CachesExplained

  • nice API
  • time based eviction
  • size based eviction
like image 147
ollins Avatar answered Apr 22 '26 22:04

ollins