Changeset 14295 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2018-10-04T19:06:23+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/CommonSettingsPanel.java
r11873 r14295 89 89 90 90 boolean restartRequired = false; 91 restartRequired |= removeCacheFiles(CachedTileLoaderFactory.PROP_TILECACHE_DIR.get(), 1024L * 1024L * ((Integer) this.maxElementsOnDisk.getValue())); 92 91 93 if (!AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.get().equals(this.maxElementsOnDisk.getValue())) { 92 if (((Integer) this.maxElementsOnDisk.getValue()) < AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.get() &&93 JCSCacheManager.USE_BLOCK_CACHE.get()) {94 // reducing size of the cache, this requires deletion of the files95 removeCacheFiles(CachedTileLoaderFactory.PROP_TILECACHE_DIR.get());96 }97 94 AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.put((Integer) this.maxElementsOnDisk.getValue()); 98 95 restartRequired = true; … … 102 99 if (!CachedTileLoaderFactory.PROP_TILECACHE_DIR.get().equals(this.tilecacheDir.getText())) { 103 100 restartRequired = true; 104 re moveCacheFiles(CachedTileLoaderFactory.PROP_TILECACHE_DIR.get()); // clear old cache directory101 restartRequired |= removeCacheFiles(CachedTileLoaderFactory.PROP_TILECACHE_DIR.get(), 0); // clear old cache directory 105 102 CachedTileLoaderFactory.PROP_TILECACHE_DIR.put(this.tilecacheDir.getText()); 106 103 } … … 114 111 } 115 112 116 private static void removeCacheFiles(String path) { 113 private static boolean removeCacheFiles(String path, long maxSize) { 114 117 115 File directory = new File(path); 118 116 File[] cacheFiles = directory.listFiles((FilenameFilter) (dir, name) -> name.endsWith(".data") || name.endsWith(".key")); 119 JCSCacheManager.shutdown(); // shutdown Cache - so files can by safely deleted117 boolean restartRequired = false; 120 118 if (cacheFiles != null) { 121 119 for (File cacheFile: cacheFiles) { 122 Utils.deleteFile(cacheFile); 120 if (cacheFile.length() > maxSize) { 121 if (!restartRequired) { 122 JCSCacheManager.shutdown(); // shutdown Cache - so files can by safely deleted 123 restartRequired = true; 124 } 125 Utils.deleteFile(cacheFile); 126 File otherFile = null; 127 if (cacheFile.getName().endsWith(".data")) { 128 otherFile = new File(cacheFile.getPath().replaceAll("\\.data$", ".key")); 129 } else if (cacheFile.getName().endsWith(".key")) { 130 otherFile = new File(cacheFile.getPath().replaceAll("\\.key$", ".data")); 131 } 132 if (otherFile != null) { 133 Utils.deleteFileIfExists(otherFile); 134 } 135 } 123 136 } 124 137 } 138 return restartRequired; 125 139 } 126 140 }
Note:
See TracChangeset
for help on using the changeset viewer.