static public void setPersistenceCache(DiskCache2 dc) { diskCache2 = dc; if (diskCache2 != null) diskCache2.setAlwaysUseCache(true); // the persistence cache file has same name as the ncml - must put it into the cache else clobber ncml 7/31/2014 }
static public void setPersistenceCache(DiskCache2 dc) { diskCache2 = dc; if (diskCache2 != null) diskCache2.setAlwaysUseCache(true); // the persistence cache file has same name as the ncml - must put it into the cache else clobber ncml 7/31/2014 }
String cacheDirName = tempFolder.newFolder().getAbsolutePath() + "/"; DiskCache2 cache = new DiskCache2(cacheDirName, false, 0, 0); cache.setAlwaysUseCache(true); Assert.assertEquals(cache.getRootDirectory(), cacheDirName); assert new File(cache.getRootDirectory()).exists();
cache.setAlwaysUseCache(true); Assert.assertEquals(cache.getRootDirectory(), cacheDirName); assert new File(cache.getRootDirectory()).exists();
@Test public void testCacheIsUsed() throws IOException, InvalidRangeException { String filename = "file:TestAggExistingCache.xml"; System.out.printf("%s%n", filename); String cacheDirName = tempFolder.newFolder().getAbsolutePath() + "/"; System.out.printf("cacheDir=%s%n", cacheDirName); File cacheDir = new File(cacheDirName); FileUtils.deleteDirectory(cacheDir); // from commons-io assert !cacheDir.exists(); DiskCache2 cache = new DiskCache2(cacheDirName, false, 0, 0); cache.setAlwaysUseCache(true); Assert.assertEquals(cache.getRootDirectory(), cacheDirName); assert new File(cache.getRootDirectory()).exists(); Aggregation.setPersistenceCache(cache); AggregationExisting.countCacheUse = 0; try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), filename, null)) { System.out.println(" TestNcmlAggExisting.open " + filename); Array ATssta = ncfile.readSection("ATssta(:,0,0,0)"); Assert.assertEquals(4, ATssta.getSize()); } Assert.assertEquals(0, AggregationExisting.countCacheUse); AggregationExisting.countCacheUse = 0; try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), filename, null)) { System.out.println(" TestNcmlAggExisting.open " + filename); Array ATssta = ncfile.readSection("ATssta(:,0,0,0)"); Assert.assertEquals(4, ATssta.getSize()); } Assert.assertEquals(8, AggregationExisting.countCacheUse); }
@BeforeClass static public void before() { GribIosp.debugIndexOnlyCount = 0; GribCollectionImmutable.countGC = 0; PartitionCollectionImmutable.countPC = 0; RandomAccessFile.enableDefaultGlobalFileCache(); RandomAccessFile.setDebugLeaks(true); // Grib.setDebugFlags(new DebugFlagsImpl("Grib/indexOnly")); GribCdmIndex.setGribCollectionCache(new ucar.nc2.util.cache.FileCacheGuava("GribCollectionCacheGuava", 100)); GribCdmIndex.gribCollectionCache.resetTracking(); // make sure that the indexes are created with the data files DiskCache2 diskCache = GribIndexCache.getDiskCache2(); diskCache.setNeverUseCache(true); diskCache.setAlwaysUseCache(false); }