* @return CacheDirectory
*/
public CacheDirectory get(String path, boolean recheck) {
requests.incrementAndGet();
Element e = cache.get(path);
if (e != null) {
if (cacheLog.isDebugEnabled()) cacheLog.debug("thredds.filesystem.CacheManager found in cache; path =" + path);
CacheDirectory m = (CacheDirectory) e.getValue();
if (m != null) { // not sure how a null m gets in here
if (!recheck) return m;
File f = new File(m.getPath()); // check if file exists and when last modified
if (!f.exists()) {
cache.put(new Element(path, null));
return null;
}
boolean modified = (f.lastModified() > m.lastModified);
if (modified && cacheLog.isDebugEnabled())
cacheLog.debug("thredds.filesystem.CacheManager modified diff = "+ (f.lastModified() - m.lastModified) + "; path=" + path);
if (!modified) {
hits.incrementAndGet();
return m;
}
// if modified, null it out and reread it
cache.put(new Element(path, null));
}
}
File p = new File(path);
if (!p.exists()) return null;