Changeset 13649 in josm for trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
- Timestamp:
- 2018-04-19T22:34:52+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
r13647 r13649 108 108 File cacheDir = new File(Config.getDirs().getCacheDirectory(true), "jcs"); 109 109 110 if (!cacheDir.exists() && !cacheDir.mkdirs()) { 111 Logging.warn("Cache directory " + cacheDir.toString() + " does not exists and could not create it"); 112 } else { 113 File cacheDirLockPath = new File(cacheDir, ".lock"); 114 try { 115 if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) { 116 Logging.warn("Cannot create cache dir lock file"); 117 } 118 cacheDirLock = FileChannel.open(cacheDirLockPath.toPath(), StandardOpenOption.WRITE).tryLock(); 119 120 if (cacheDirLock == null) 121 Logging.warn("Cannot lock cache directory. Will not use disk cache"); 122 } catch (IOException e) { 123 Logging.warn("Cannot create cache dir \"" + cacheDirLockPath.toString() + "\" lock file: " + e.toString()); 124 Logging.warn("Will not use disk cache"); 110 try { 111 if (!cacheDir.exists() && !cacheDir.mkdirs()) { 112 Logging.warn("Cache directory " + cacheDir.toString() + " does not exists and could not create it"); 113 } else { 114 File cacheDirLockPath = new File(cacheDir, ".lock"); 115 try { 116 if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) { 117 Logging.warn("Cannot create cache dir lock file"); 118 } 119 cacheDirLock = FileChannel.open(cacheDirLockPath.toPath(), StandardOpenOption.WRITE).tryLock(); 120 121 if (cacheDirLock == null) 122 Logging.warn("Cannot lock cache directory. Will not use disk cache"); 123 } catch (IOException e) { 124 Logging.warn("Cannot create cache dir \"" + cacheDirLockPath.toString() + "\" lock file: " + e.toString()); 125 Logging.warn("Will not use disk cache"); 126 } 125 127 } 126 } 128 } catch (SecurityException e) { 129 Logging.log(Logging.LEVEL_WARN, "Unable to configure disk cache. Will not use it", e); 130 } 131 127 132 // this could be moved to external file 128 133 Properties props = new Properties(); … … 140 145 props.setProperty("jcs.default.elementattributes.IsSpool", "true"); 141 146 // CHECKSTYLE.ON: SingleSpaceSeparator 142 CompositeCacheManager cm = CompositeCacheManager.getUnconfiguredInstance(); 143 cm.configure(props); 144 cacheManager = cm; 147 try { 148 CompositeCacheManager cm = CompositeCacheManager.getUnconfiguredInstance(); 149 cm.configure(props); 150 cacheManager = cm; 151 } catch (SecurityException e) { 152 Logging.log(Logging.LEVEL_WARN, "Unable to initialize JCS", e); 153 } 145 154 } 146 155 … … 173 182 if (cacheManager == null) 174 183 initialize(); 175 return getCacheInner(cacheName, maxMemoryObjects, maxDiskObjects, cachePath);184 return cacheManager != null ? getCacheInner(cacheName, maxMemoryObjects, maxDiskObjects, cachePath) : null; 176 185 } 177 186 }
Note:
See TracChangeset
for help on using the changeset viewer.