/** * Acquire a FileCacheable, and lock it so no one else can use it. * call FileCacheable.close() when done. * * @param factory use this factory to open the file; may not be null * @param location file location, also used as the cache name, will be passed to the NetcdfFileFactory * @return NetcdfFile corresponding to location. * @throws IOException on error */ @Override public FileCacheable acquire(FileFactory factory, String location) throws IOException { return acquire(factory, location, location, -1, null, null); }
/** * Disable the cache, and force release all files. * You must still call shutdown() before exiting the application. */ @Override public void disable() { this.disabled.set(true); clearCache(true); }
private void removeFromCache(int count) { int done = 0; while (count > done) { CacheElement elem = shadowCache.lastKey(); done += elem.list.size(); expireFromCache(elem); } }
cacheLog.debug("FileCacheARC " + name + ": acquire from cache " + hashKey + " " + want.ncfile.getLocation() + " was changed; discard"); expireFromCache(wantCacheElem); return null; updateInCache(wantCacheElem); return want.ncfile;
FileCacheable ncfile = acquireCacheOnly(hashKey); if (ncfile != null) { hits.incrementAndGet(); addToCache(hashKey, ncfile);
private void addToCache(Object hashKey, FileCacheable ncfile) { CacheElement newCacheElem = new CacheElement(hashKey); CacheElement previous = cache.putIfAbsent(hashKey, newCacheElem); // add new element if doesnt exist CacheElement elem = (previous != null) ? previous : newCacheElem; // use previous if it exists elem.addFile(ncfile); // add to existing list shadowCache.put(newCacheElem, newCacheElem); int size = cacheSize.getAndIncrement(); if (size > softLimit) { removeFromCache(size - softLimit); } }
/** * Show individual cache entries, add to formatter. * * @param format add to this */ @Override public void showCache(Formatter format) { ArrayList<CacheElement.CacheFile> allFiles = new ArrayList<>(files.size()); for (CacheElement elem : cache.values()) { allFiles.addAll(elem.list); } Collections.sort(allFiles); // sort so oldest are on top format.format("%nFileCacheARC %s (min=%d softLimit=%d hardLimit=%d scour=%d):%n", name, minElements, softLimit, hardLimit, period); format.format("isLocked accesses lastAccess location %n"); for (CacheElement.CacheFile file : allFiles) { String loc = file.ncfile != null ? file.ncfile.getLocation() : "null"; CalendarDate cd = CalendarDate.of(file.getLastAccessed()); format.format("%8s %9d %s %s %n", file.isLocked, file.getCountAccessed(), CalendarDateFormatter.toTimeUnits(cd), loc); } showStats(format); }
cacheLog.debug("FileCacheARC " + name + ": acquire from cache " + hashKey + " " + want.ncfile.getLocation() + " was changed; discard"); expireFromCache(wantCacheElem); return null; updateInCache(wantCacheElem); return want.ncfile;
FileCacheable ncfile = acquireCacheOnly(hashKey); if (ncfile != null) { hits.incrementAndGet(); addToCache(hashKey, ncfile);
private void addToCache(Object hashKey, FileCacheable ncfile) { CacheElement newCacheElem = new CacheElement(hashKey); CacheElement previous = cache.putIfAbsent(hashKey, newCacheElem); // add new element if doesnt exist CacheElement elem = (previous != null) ? previous : newCacheElem; // use previous if it exists elem.addFile(ncfile); // add to existing list shadowCache.put(newCacheElem, newCacheElem); int size = cacheSize.getAndIncrement(); if (size > softLimit) { removeFromCache(size - softLimit); } }
/** * Show individual cache entries, add to formatter. * * @param format add to this */ @Override public void showCache(Formatter format) { ArrayList<CacheElement.CacheFile> allFiles = new ArrayList<>(files.size()); for (CacheElement elem : cache.values()) { allFiles.addAll(elem.list); } Collections.sort(allFiles); // sort so oldest are on top format.format("%nFileCacheARC %s (min=%d softLimit=%d hardLimit=%d scour=%d):%n", name, minElements, softLimit, hardLimit, period); format.format("isLocked accesses lastAccess location %n"); for (CacheElement.CacheFile file : allFiles) { String loc = file.ncfile != null ? file.ncfile.getLocation() : "null"; CalendarDate cd = CalendarDate.of(file.getLastAccessed()); format.format("%8s %9d %s %s %n", file.isLocked, file.getCountAccessed(), CalendarDateFormatter.toTimeUnits(cd), loc); } showStats(format); }
private void removeFromCache(int count) { int done = 0; while (count > done) { CacheElement elem = shadowCache.lastKey(); done += elem.list.size(); expireFromCache(elem); } }
/** * Disable the cache, and force release all files. * You must still call shutdown() before exiting the application. */ @Override public void disable() { this.disabled.set(true); clearCache(true); }
/** * Acquire a FileCacheable, and lock it so no one else can use it. * call FileCacheable.close() when done. * * @param factory use this factory to open the file; may not be null * @param location file location, also used as the cache name, will be passed to the NetcdfFileFactory * @return NetcdfFile corresponding to location. * @throws IOException on error */ @Override public FileCacheable acquire(FileFactory factory, DatasetUrl location) throws IOException { return acquire(factory, location.trueurl, location, -1, null, null); }