public synchronized void clearCache ( boolean force ) { List < CacheElement . CacheFile > deleteList = new ArrayList <> ( 2 * cache . size ( ) ) ; if ( force ) { cache . clear ( ) ; // deletes everything from the cache deleteList . addAll ( files . values ( ) ) ; // add everything to the delete list files . clear ( ) ; // counter.set(0); } else { // add unlocked files to the delete list, remove from files hash Iterator < CacheElement . CacheFile > iter = files . values ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { CacheElement . CacheFile file = iter . next ( ) ; if ( file . isLocked . compareAndSet ( false , true ) ) { file . remove ( ) ; // remove from the containing CacheElement deleteList . add ( file ) ; iter . remove ( ) ; } } // remove empty cache elements for ( CacheElement elem : cache . values ( ) ) { if ( elem . list . size ( ) == 0 ) cache . remove ( elem . hashKey ) ; } } // close all files in deleteList for ( CacheElement . CacheFile file : deleteList ) { if ( force && file . isLocked . get ( ) ) cacheLog . warn ( "FileCacheARC " + name + " force close locked file= " + file ) ; //counter.decrementAndGet(); if ( file . ncfile == null ) continue ; try { file . ncfile . setFileCache ( null ) ; file . ncfile . close ( ) ; file . ncfile = null ; // help the gc } catch ( IOException e ) { log . error ( "FileCacheARC " + name + " close failed on " + file ) ; } } if ( cacheLog . isDebugEnabled ( ) ) cacheLog . debug ( "*FileCacheARC " + name + " clearCache force= " + force + " deleted= " + deleteList . size ( ) + " left=" + files . size ( ) ) ; //System.out.println("\n*NetcdfFileCache.clearCache force= " + force + " deleted= " + deleteList.size() + " left=" + counter.get()); }
Remove all cache entries .