diff --git src/org/openstreetmap/gui/jmapviewer/interfaces/CachedTileLoader.java src/org/openstreetmap/gui/jmapviewer/interfaces/CachedTileLoader.java
index 07928c6..efa50d4 100644
|
|
package org.openstreetmap.gui.jmapviewer.interfaces;
|
5 | 5 | * Interface that allow cleaning the tile cache without specifying exact type of loader |
6 | 6 | */ |
7 | 7 | public interface CachedTileLoader { |
8 | | public void clearCache(); |
| 8 | public void clearCache(TileSource source); |
9 | 9 | } |
diff --git src/org/openstreetmap/josm/data/cache/JCSCacheManager.java src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
index bddfb28..8f3f70d 100644
|
|
|
2 | 2 | package org.openstreetmap.josm.data.cache; |
3 | 3 | |
4 | 4 | import java.io.File; |
| 5 | import java.io.FileOutputStream; |
5 | 6 | import java.io.IOException; |
| 7 | import java.nio.channels.FileLock; |
6 | 8 | import java.text.MessageFormat; |
7 | 9 | import java.util.Properties; |
8 | 10 | import java.util.logging.Handler; |
… |
… |
public class JCSCacheManager {
|
39 | 41 | private static long maxObjectTTL = Long.MAX_VALUE; |
40 | 42 | private final static String PREFERENCE_PREFIX = "jcs.cache"; |
41 | 43 | private final static IndexedDiskCacheFactory diskCacheFactory = new IndexedDiskCacheFactory(); |
| 44 | private static FileLock cacheDirLock = null; |
42 | 45 | |
43 | 46 | /** |
44 | 47 | * default objects to be held in memory by JCS caches (per region) |
45 | 48 | */ |
46 | 49 | public static final IntegerProperty DEFAULT_MAX_OBJECTS_IN_MEMORY = new IntegerProperty(PREFERENCE_PREFIX + ".max_objects_in_memory", 1000); |
47 | 50 | |
| 51 | @SuppressWarnings("resource") |
48 | 52 | private static void initialize() throws IOException { |
49 | 53 | File cacheDir = new File(Main.pref.getCacheDirectory(), "jcs"); |
50 | 54 | |
51 | 55 | if ((!cacheDir.exists() && !cacheDir.mkdirs())) |
52 | 56 | throw new IOException("Cannot access cache directory"); |
53 | 57 | |
| 58 | File cacheDirLockPath = new File(cacheDir, ".lock"); |
| 59 | if (!cacheDirLockPath.exists()) |
| 60 | cacheDirLockPath.createNewFile(); |
| 61 | cacheDirLock = new FileOutputStream(cacheDirLockPath).getChannel().tryLock(); |
| 62 | |
| 63 | if (cacheDirLock == null) |
| 64 | log.log(Level.WARNING, "Cannot lock cache directory. Will not use disk cache"); |
| 65 | |
54 | 66 | // raising logging level gives ~500x performance gain |
55 | 67 | // http://westsworld.dk/blog/2008/01/jcs-and-performance/ |
56 | 68 | Logger jcsLog = Logger.getLogger("org.apache.commons.jcs"); |
… |
… |
public class JCSCacheManager {
|
138 | 150 | private static <K,V> CacheAccess<K, V> getCacheInner(String cacheName, int maxMemoryObjects, int maxDiskObjects, String cachePath) { |
139 | 151 | CompositeCache<K, V> cc = cacheManager.getCache(cacheName, getCacheAttributes(maxMemoryObjects)); |
140 | 152 | |
141 | | if (cachePath != null) { |
| 153 | if (cachePath != null && cacheDirLock != null) { |
142 | 154 | IndexedDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath); |
143 | 155 | diskAttributes.setCacheName(cacheName); |
144 | 156 | IndexedDiskCache<K, V> diskCache = diskCacheFactory.createCache(diskAttributes, cacheManager, null, new StandardSerializer()); |
diff --git src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoader.java src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoader.java
index d2709aa..6b612e9 100644
|
|
public class TMSCachedTileLoader implements TileLoader, CachedTileLoader, TileCa
|
61 | 61 | } |
62 | 62 | |
63 | 63 | @Override |
64 | | public void clearCache() { |
| 64 | public void clearCache(TileSource source) { |
65 | 65 | this.cache.clear(); |
66 | 66 | } |
67 | 67 | |
diff --git src/org/openstreetmap/josm/gui/layer/TMSLayer.java src/org/openstreetmap/josm/gui/layer/TMSLayer.java
index 1b5e05b..a496320 100644
|
|
public class TMSLayer extends ImageryLayer implements ImageObserver, TileLoaderL
|
193 | 193 | void clearTileCache(ProgressMonitor monitor) { |
194 | 194 | tileCache.clear(); |
195 | 195 | if (tileLoader instanceof CachedTileLoader) { |
196 | | ((CachedTileLoader)tileLoader).clearCache(); |
| 196 | ((CachedTileLoader)tileLoader).clearCache(tileSource); |
197 | 197 | } |
198 | 198 | } |
199 | 199 | |