@@ -0,0 +1,1241 @@
+/**%0A * %0A */%0Apackage com.trendrr.oss;%0A%0Aimport java.util.concurrent.ConcurrentHashMap;%0A%0Aimport org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0A%0Aimport com.trendrr.oss.concurrent.ReinitObject;%0A%0A%0A/**%0A * %0A * A threadsafe file cache.%0A * %0A * %0A * @author Dustin Norlander%0A * @created Apr 7, 2011%0A * %0A */%0Apublic class FileCache %7B%0A%0A%09protected Log log = LogFactory.getLog(FileCache.class);%0A%09%0A%09private static ConcurrentHashMap%3CString, ReinitObject%3Cbyte%5B%5D%3E%3E cache = new ConcurrentHashMap%3CString, ReinitObject%3Cbyte%5B%5D%3E%3E ();%0A%09%0A%09%0A%09/**%0A%09 * loads a file from the cache.  All exceptions are logged as warnings, and null is returned.%0A%09 * @param filename filename to load%0A%09 * @param timeoutPeriod number of milliseconds between reload of the file.%0A%09 * @return%0A%09 */%0A%09public byte%5B%5D getFileBytes(String filename, long timeoutPeriod) %7B%0A%09%09final String f = filename;%0A%09%09%0A%09%09//fancy timeout cache. %0A%09%09cache.putIfAbsent(filename, new ReinitObject%3Cbyte%5B%5D%3E(timeoutPeriod) %7B%0A%09%09%09@Override%0A%09%09%09public byte%5B%5D init() %7B%0A%09%09%09%09try %7B%0A%09%09%09%09%09System.out.println(%22LOADING FROM FILE SYSTEM!%22);%0A%09%09%09%09%09return FileHelper.loadBytes(f);%0A%09%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09%09log.warn(%22Caught%22, e);%0A%09%09%09%09%7D%0A%09%09%09%09return null;%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09return cache.get(filename).get();%0A%09%7D%0A%7D%0A

Add a simple, fast, threadsafe file cache