Index: trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java	(revision 8185)
+++ trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java	(revision 8186)
@@ -3,5 +3,7 @@
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.nio.channels.FileLock;
 import java.text.MessageFormat;
 import java.util.Properties;
@@ -40,4 +42,5 @@
     private final static String PREFERENCE_PREFIX = "jcs.cache";
     private final static IndexedDiskCacheFactory diskCacheFactory = new IndexedDiskCacheFactory();
+    private static FileLock cacheDirLock = null;
 
     /**
@@ -46,4 +49,5 @@
     public static final IntegerProperty DEFAULT_MAX_OBJECTS_IN_MEMORY  = new IntegerProperty(PREFERENCE_PREFIX + ".max_objects_in_memory", 1000);
 
+    @SuppressWarnings("resource")
     private static void initialize() throws IOException {
         File cacheDir = new File(Main.pref.getCacheDirectory(), "jcs");
@@ -51,4 +55,12 @@
         if ((!cacheDir.exists() && !cacheDir.mkdirs()))
             throw new IOException("Cannot access cache directory");
+
+        File cacheDirLockPath = new File(cacheDir, ".lock");
+        if (!cacheDirLockPath.exists())
+            cacheDirLockPath.createNewFile();
+        cacheDirLock = new FileOutputStream(cacheDirLockPath).getChannel().tryLock();
+
+        if (cacheDirLock == null)
+            log.log(Level.WARNING, "Cannot lock cache directory. Will not use disk cache");
 
         // raising logging level gives ~500x performance gain
@@ -139,5 +151,5 @@
         CompositeCache<K, V> cc = cacheManager.getCache(cacheName, getCacheAttributes(maxMemoryObjects));
 
-        if (cachePath != null) {
+        if (cachePath != null && cacheDirLock != null) {
             IndexedDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath);
             diskAttributes.setCacheName(cacheName);
Index: trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoader.java	(revision 8185)
+++ trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoader.java	(revision 8186)
@@ -62,5 +62,5 @@
 
     @Override
-    public void clearCache() {
+    public void clearCache(TileSource source) {
         this.cache.clear();
     }
Index: trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java	(revision 8185)
+++ trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java	(revision 8186)
@@ -194,5 +194,5 @@
         tileCache.clear();
         if (tileLoader instanceof CachedTileLoader) {
-            ((CachedTileLoader)tileLoader).clearCache();
+            ((CachedTileLoader)tileLoader).clearCache(tileSource);
         }
     }
