- Timestamp:
- 2018-04-16T23:00:30+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 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 } -
trunk/src/org/openstreetmap/josm/gui/layer/AbstractCachedTileSourceLayer.java
r12620 r13643 2 2 package org.openstreetmap.josm.gui.layer; 3 3 4 import java.io.IOException;5 4 import java.util.Map; 6 5 import java.util.concurrent.ConcurrentHashMap; … … 16 15 import org.openstreetmap.josm.data.imagery.TileLoaderFactory; 17 16 import org.openstreetmap.josm.data.preferences.IntegerProperty; 18 import org.openstreetmap.josm.tools.Logging;19 17 20 18 /** … … 84 82 return cache; 85 83 } 86 try { 87 cache = JCSCacheManager.getCache(getCacheName(), 88 0, 89 getDiskCacheSize(), 90 CachedTileLoaderFactory.PROP_TILECACHE_DIR.get()); 91 return cache; 92 } catch (IOException e) { 93 Logging.warn(e); 94 return null; 95 } 84 cache = JCSCacheManager.getCache(getCacheName(), 85 0, 86 getDiskCacheSize(), 87 CachedTileLoaderFactory.PROP_TILECACHE_DIR.get()); 88 return cache; 96 89 } 97 90 … … 125 118 */ 126 119 public static CacheAccess<String, BufferedImageCacheEntry> getCache(String name) { 127 try { 128 return JCSCacheManager.getCache(name, 129 0, 130 MAX_DISK_CACHE_SIZE.get() * 1024, // MAX_DISK_CACHE_SIZE is in MB, needs to by in sync with getDiskCacheSize 131 CachedTileLoaderFactory.PROP_TILECACHE_DIR.get()); 132 } catch (IOException e) { 133 Logging.warn(e); 134 return null; 135 } 120 return JCSCacheManager.getCache(name, 121 0, 122 MAX_DISK_CACHE_SIZE.get() * 1024, // MAX_DISK_CACHE_SIZE is in MB, needs to by in sync with getDiskCacheSize 123 CachedTileLoaderFactory.PROP_TILECACHE_DIR.get()); 136 124 } 137 125 -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ThumbsLoader.java
r13127 r13643 68 68 private void initCache() { 69 69 if (!cacheOff) { 70 try { 71 cache = JCSCacheManager.getCache("geoimage-thumbnails", 0, 120, 72 Config.getDirs().getCacheDirectory(true).getPath() + File.separator + "geoimage-thumbnails"); 73 } catch (IOException e) { 74 Logging.warn("Failed to initialize cache for geoimage-thumbnails"); 75 Logging.warn(e); 76 } 70 cache = JCSCacheManager.getCache("geoimage-thumbnails", 0, 120, 71 Config.getDirs().getCacheDirectory(true).getPath() + File.separator + "geoimage-thumbnails"); 77 72 } 78 73 }
Note:
See TracChangeset
for help on using the changeset viewer.