Changeset 10323 in josm
- Timestamp:
- 2016-06-04T16:28:04+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
r10235 r10323 19 19 import org.apache.commons.jcs.auxiliary.disk.block.BlockDiskCacheAttributes; 20 20 import org.apache.commons.jcs.auxiliary.disk.block.BlockDiskCacheFactory; 21 import org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes; 22 import org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory; 21 23 import org.apache.commons.jcs.engine.CompositeCacheAttributes; 22 24 import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes.DiskUsagePattern; … … 26 28 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; 27 29 import org.openstreetmap.josm.Main; 30 import org.openstreetmap.josm.data.preferences.BooleanProperty; 28 31 import org.openstreetmap.josm.data.preferences.IntegerProperty; 29 32 … … 41 44 private static long maxObjectTTL = -1; 42 45 private static final String PREFERENCE_PREFIX = "jcs.cache"; 43 private static final AuxiliaryCacheFactory diskCacheFactory = new BlockDiskCacheFactory(); 46 private static BooleanProperty USE_BLOCK_CACHE = new BooleanProperty(PREFERENCE_PREFIX + ".use_block_cache", true); 47 48 private static final AuxiliaryCacheFactory diskCacheFactory = 49 USE_BLOCK_CACHE.get() ? new BlockDiskCacheFactory() : new IndexedDiskCacheFactory(); 44 50 private static FileLock cacheDirLock; 45 51 … … 163 169 164 170 if (cachePath != null && cacheDirLock != null) { 165 IDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath); 166 diskAttributes.setCacheName(cacheName); 171 IDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath, cacheName); 167 172 try { 168 173 if (cc.getAuxCaches().length == 0) { … … 190 195 } 191 196 192 private static IDiskCacheAttributes getDiskCacheAttributes(int maxDiskObjects, String cachePath) { 193 BlockDiskCacheAttributes ret = new BlockDiskCacheAttributes(); 197 private static IDiskCacheAttributes getDiskCacheAttributes(int maxDiskObjects, String cachePath, String cacheName) { 198 IDiskCacheAttributes ret; 199 if (USE_BLOCK_CACHE.get()) { 200 BlockDiskCacheAttributes blockAttr = new BlockDiskCacheAttributes(); 201 blockAttr.setMaxKeySize(maxDiskObjects); 202 ret = blockAttr; 203 } else { 204 IndexedDiskCacheAttributes indexAttr = new IndexedDiskCacheAttributes(); 205 indexAttr.setMaxKeySize(maxDiskObjects); 206 ret = indexAttr; 207 } 194 208 ret.setDiskLimitType(IDiskCacheAttributes.DiskLimitType.SIZE); 195 ret.setMaxKeySize(maxDiskObjects);196 if ( cachePath != null) {197 File path = new File(cachePath);198 if (!path.exists() && !path.mkdirs()){199 LOG.log(Level.WARNING, "Failed to create cache path: {0}",cachePath);200 } else {201 ret.setDiskPath(path);202 } 203 }209 File path = new File(cachePath); 210 if (!path.exists() && !path.mkdirs()) { 211 LOG.log(Level.WARNING, "Failed to create cache path: {0}", cachePath); 212 } else { 213 ret.setDiskPath(cachePath); 214 } 215 ret.setCacheName(cacheName + (USE_BLOCK_CACHE.get() ? "_BLOCK" : "_INDEX")); 216 217 removeStaleFiles(cachePath + File.separator + cacheName, (USE_BLOCK_CACHE.get() ? "_INDEX" : "_BLOCK")); 204 218 return ret; 219 } 220 221 private static void removeStaleFiles(String basePathPart, String suffix) { 222 deleteCacheFiles(basePathPart); // TODO: this can be removed around 2016.09 223 deleteCacheFiles(basePathPart + suffix); 224 } 225 226 private static void deleteCacheFiles(String basePathPart) { 227 new File(basePathPart + ".key").delete(); 228 new File(basePathPart + ".data").delete(); 205 229 } 206 230
Note:
See TracChangeset
for help on using the changeset viewer.