@Override
  public FileCacheable acquire(FileFactory factory, Object hashKey, DatasetUrl location,
                               int buffer_size, CancelTask cancelTask, Object spiObject) throws IOException {

    if (null == hashKey) hashKey = location.trueurl;
    if (null == hashKey) throw new IllegalArgumentException();

    Tracker t = null;
    if (trackAll) {
      t = new Tracker(hashKey);
      Tracker prev = track.putIfAbsent(hashKey, t);
      if (prev != null) t = prev;
    }

    FileCacheable ncfile = acquireCacheOnly(hashKey);
    if (ncfile != null) {
      hits.incrementAndGet();
      if (t != null) t.hit++;
      return ncfile;
    }
    miss.incrementAndGet();
    if (t != null) t.miss++;

    // open the file
    ncfile = factory.open(location, buffer_size, cancelTask, spiObject);
    if (cacheLog.isDebugEnabled())
      cacheLog.debug("FileCacheARC " + name + " acquire " + hashKey + " " + ncfile.getLocation());
    if (debugPrint) System.out.println("  FileCacheARC " + name + " acquire " + hashKey + " " + ncfile.getLocation());

    // user may have canceled
    if ((cancelTask != null) && (cancelTask.isCancel())) {
      if (ncfile != null) ncfile.close();
      return null;
    }

    if (disabled.get()) return ncfile;

    addToCache(hashKey, ncfile);

    return ncfile;
  }
@ Override public FileCacheable acquire ( FileFactory factory , Object hashKey , DatasetUrl location , int buffer_size , CancelTask cancelTask , Object spiObject ) throws IOException { if ( null == hashKey ) hashKey = location . trueurl ; if ( null == hashKey ) throw new IllegalArgumentException ( ) ; Tracker t = null ; if ( trackAll ) { t = new Tracker ( hashKey ) ; Tracker prev = track . putIfAbsent ( hashKey , t ) ; if ( prev != null ) t = prev ; } FileCacheable ncfile = acquireCacheOnly ( hashKey ) ; if ( ncfile != null ) { hits . incrementAndGet ( ) ; if ( t != null ) t . hit ++ ; return ncfile ; } miss . incrementAndGet ( ) ; if ( t != null ) t . miss ++ ; ncfile = factory . open ( location , buffer_size , cancelTask , spiObject ) ; if ( cacheLog . isDebugEnabled ( ) ) cacheLog . debug ( "FileCacheARC " + name + " acquire " + hashKey + " " + ncfile . getLocation ( ) ) ; if ( debugPrint ) System . out . println ( "  FileCacheARC " + name + " acquire " + hashKey + " " + ncfile . getLocation ( ) ) ; if ( ( cancelTask != null ) && ( cancelTask . isCancel ( ) ) ) { if ( ncfile != null ) ncfile . close ( ) ; return null ; } if ( disabled . get ( ) ) return ncfile ; addToCache ( hashKey , ncfile ) ; return ncfile ; }
Acquire a FileCacheable from the cache, and lock it so no one else can use it.
If not already in cache, open it with FileFactory, and put in cache.
<p/>
Call FileCacheable.close() when done, (rather than FileCacheIF.release() directly) and the file is then released instead of closed.
<p/>
If cache size goes over maxElement, then immediately (actually in 100 msec) schedule a cleanup in a background thread.
This means that the cache should never get much larger than maxElement, unless you have them all locked.

@param factory     use this factory to open the file if not in the cache; may not be null
@param hashKey     unique key for this file. If null, the location will be used
@param location    file location, may also used as the cache name, will be passed to the NetcdfFileFactory
@param buffer_size RandomAccessFile buffer size, if <= 0, use default size
@param cancelTask  user can cancel, ok to be null.
@param spiObject   sent to iosp.setSpecial() if not null
@return FileCacheable corresponding to location.
@throws IOException on error