cdm/src/main/java/ucar/nc2/util/cache/FileCache.java
private FileCacheable acquireCacheOnly(Object hashKey) {
    if (disabled.get()) return null;

    // see if its in the cache
    CacheElement wantCacheElem = cache.get(hashKey);
    if (wantCacheElem == null) return null;  // not found in cache

    CacheElement.CacheFile want = null;
    synchronized (wantCacheElem) { // synch in order to traverse the list
      for (CacheElement.CacheFile file : wantCacheElem.list) {
        if (file.isLocked.compareAndSet(false, true)) {
          want = file;
          break;
        }
      }
    }
    if (want == null) return null; // no unlocked file in cache

    // check if modified, remove if so
    if (want.ncfile != null) {
      long lastModified = want.ncfile.getLastModified();
      boolean changed = lastModified != want.lastModified;

      if (cacheLog.isDebugEnabled() && changed)
        cacheLog.debug("FileCache " + name + ": acquire from cache " + hashKey + " " + want.ncfile.getLocation() + " was changed; discard");
      if (changed) {
        remove(want);
      }
    }

    if (want.ncfile != null) {
      try {
        want.ncfile.reacquire(); // rehydrate
      } catch (IOException ioe) {
        if (cacheLog.isDebugEnabled())
          cacheLog.debug("FileCache " + name + " acquire from cache " + hashKey + " " + want.ncfile.getLocation() +
                         " failed: " + ioe.getMessage());
        remove(want);  // failed
      }
    }

    if (debugPrint && want.ncfile != null) {
      System.out.printf("  FileCache %s found in cache %s (countLocks %d)%n", name, hashKey, countLocked());
    }

    return want.ncfile;
  }
private FileCacheable acquireCacheOnly(Object hashKey) {
    if (disabled.get()) return null;

    // see if its in the cache
    CacheElement wantCacheElem = cache.get(hashKey);
    if (wantCacheElem == null) return null;  // not found in cache

    CacheElement.CacheFile want = null;
    synchronized (wantCacheElem) { // synch in order to traverse the list
      for (CacheElement.CacheFile file : wantCacheElem.list) {
        if (file.isLocked.compareAndSet(false, true)) {
          want = file;
          break;
        }
      }
    }
    if (want == null) return null; // no unlocked file in cache

    // check if modified, remove if so
    if (want.ncfile != null) {
      long lastModified = want.ncfile.getLastModified();
      boolean changed = lastModified != want.lastModified;

      if (cacheLog.isDebugEnabled() && changed)
        cacheLog.debug("FileCache " + name + ": acquire from cache " + hashKey + " " + want.ncfile.getLocation() + " was changed; discard");
      if (changed) {
        remove(want);
      }
    }

    if (want.ncfile != null) {
      try {
        want.ncfile.reacquire(); // rehydrate
      } catch (IOException ioe) {
        if (cacheLog.isDebugEnabled())
          cacheLog.debug("FileCache " + name + " acquire from cache " + hashKey + " " + want.ncfile.getLocation() +
                         " failed: " + ioe.getMessage());
        remove(want);  // failed
      }
    }

    if (debugPrint && want.ncfile != null) {
      System.out.printf("  FileCache %s found in cache %s (countLocks %d)%n", name, hashKey, countLocked());
    }

    return want.ncfile;
  }
private FileCacheable acquireCacheOnly ( Object hashKey ) { if ( disabled . get ( ) ) return null ; // see if its in the cache
 CacheElement wantCacheElem = cache . get ( hashKey ) ; if ( wantCacheElem == null ) return null ; // not found in cache
 CacheElement . CacheFile want = null ; synchronized ( wantCacheElem ) { // synch in order to traverse the list
 for ( CacheElement . CacheFile file : wantCacheElem . list ) { if ( file . isLocked . compareAndSet ( false , true ) ) { want = file ; break ; } } } if ( want == null ) return null ; // no unlocked file in cache
 // check if modified, remove if so
 if ( want . ncfile != null ) { long lastModified = want . ncfile . getLastModified ( ) ; boolean changed = lastModified != want . lastModified ; if ( cacheLog . isDebugEnabled ( ) && changed ) cacheLog . debug ( "FileCache " + name + ": acquire from cache " + hashKey + " " + want . ncfile . getLocation ( ) + " was changed; discard" ) ; if ( changed ) { remove ( want ) ; } } if ( want . ncfile != null ) { try { want . ncfile . reacquire ( ) ; // rehydrate
 } catch ( IOException ioe ) { if ( cacheLog . isDebugEnabled ( ) ) cacheLog . debug ( "FileCache " + name + " acquire from cache " + hashKey + " " + want . ncfile . getLocation ( ) + " failed: " + ioe . getMessage ( ) ) ; remove ( want ) ; // failed
 } } if ( debugPrint && want . ncfile != null ) { System . out . printf ( "  FileCache %s found in cache %s (countLocks %d)%n" , name , hashKey , countLocked ( ) ) ; } return want . ncfile ; }
Try to find a file in the cache.

@param hashKey used as the key.
@return file if its in the cache, null otherwise.
Try to find a file in the cache .