Changeset 13643 in josm for trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
- Timestamp:
- 2018-04-16T23:00:30+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
r13204 r13643 101 101 102 102 @SuppressWarnings("resource") 103 private static void initialize() throws IOException{103 private static void initialize() { 104 104 File cacheDir = new File(Config.getDirs().getCacheDirectory(true), "jcs"); 105 105 106 if (!cacheDir.exists() && !cacheDir.mkdirs()) 107 throw new IOException("Cannot access cache directory"); 108 109 File cacheDirLockPath = new File(cacheDir, ".lock"); 110 if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) { 111 Logging.warn("Cannot create cache dir lock file"); 112 } 113 cacheDirLock = FileChannel.open(cacheDirLockPath.toPath(), StandardOpenOption.WRITE).tryLock(); 114 115 if (cacheDirLock == null) 116 Logging.warn("Cannot lock cache directory. Will not use disk cache"); 117 106 if (!cacheDir.exists() && !cacheDir.mkdirs()) { 107 Logging.warn("Cache directory " + cacheDir.toString() + " does not exists and could not create it"); 108 } else { 109 File cacheDirLockPath = new File(cacheDir, ".lock"); 110 try { 111 if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) { 112 Logging.warn("Cannot create cache dir lock file"); 113 } 114 cacheDirLock = FileChannel.open(cacheDirLockPath.toPath(), StandardOpenOption.WRITE).tryLock(); 115 116 if (cacheDirLock == null) 117 Logging.warn("Cannot lock cache directory. Will not use disk cache"); 118 } catch (IOException e) { 119 Logging.warn("Cannot create cache dir \"" + cacheDirLockPath.toString() + "\" lock file: " + e.toString()); 120 Logging.warn("Will not use disk cache"); 121 } 122 } 118 123 // this could be moved to external file 119 124 Properties props = new Properties(); … … 142 147 * @param cacheName region name 143 148 * @return cache access object 144 * @throws IOException if directory is not found 145 */ 146 public static <K, V> CacheAccess<K, V> getCache(String cacheName) throws IOException { 149 */ 150 public static <K, V> CacheAccess<K, V> getCache(String cacheName) { 147 151 return getCache(cacheName, DEFAULT_MAX_OBJECTS_IN_MEMORY.get().intValue(), 0, null); 148 152 } … … 157 161 * @param cachePath path to disk cache. if null, no disk cache will be created 158 162 * @return cache access object 159 * @throws IOException if directory is not found 160 */ 161 public static <K, V> CacheAccess<K, V> getCache(String cacheName, int maxMemoryObjects, int maxDiskObjects, String cachePath) 162 throws IOException { 163 */ 164 public static <K, V> CacheAccess<K, V> getCache(String cacheName, int maxMemoryObjects, int maxDiskObjects, String cachePath) { 163 165 if (cacheManager != null) 164 166 return getCacheInner(cacheName, maxMemoryObjects, maxDiskObjects, cachePath); … … 172 174 173 175 @SuppressWarnings("unchecked") 174 private static <K, V> CacheAccess<K, V> getCacheInner(String cacheName, int maxMemoryObjects, int maxDiskObjects, String cachePath) 175 throws IOException { 176 private static <K, V> CacheAccess<K, V> getCacheInner(String cacheName, int maxMemoryObjects, int maxDiskObjects, String cachePath) { 176 177 CompositeCache<K, V> cc = cacheManager.getCache(cacheName, getCacheAttributes(maxMemoryObjects)); 177 178 … … 183 184 diskAttributes, cacheManager, null, new StandardSerializer())}); 184 185 } 185 } catch (IOException e) { 186 throw e; 187 } catch (Exception e) { // NOPMD 188 throw new IOException(e); 186 } catch (Exception e) { 187 // in case any error in setting auxiliary cache, do not use disk cache at all - only memory 188 cc.setAuxCaches(new AuxiliaryCache[0]); 189 189 } 190 190 }
Note:
See TracChangeset
for help on using the changeset viewer.