Index: wmsplugin/src/wmsplugin/Cache.java
===================================================================
--- wmsplugin/src/wmsplugin/Cache.java	(revision 13813)
+++ wmsplugin/src/wmsplugin/Cache.java	(working copy)
@@ -3,12 +3,15 @@
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.FileFilter;
+import java.math.BigInteger;
+import java.security.MessageDigest;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.Set;
 import java.util.TreeMap;
 import javax.imageio.*;
 
+
 import org.openstreetmap.josm.Main;
 
 public class Cache {
@@ -126,11 +129,21 @@
         );
     }
 
-    private String clean(String ident) {
-        return ident.replaceAll("[^a-zA-Z0-9]", "");
+    private static String getUniqueFilename(String ident) {
+        try {
+            MessageDigest md = MessageDigest.getInstance("MD5");
+            BigInteger number = new BigInteger(1, md.digest(ident.getBytes()));
+            return number.toString(16);
+        } catch(Exception e) {
+            // Fall back. Remove unsuitable characters and some random ones to shrink down path length.
+            // Limit it to 70 characters, that leaves about 190 for the path on Windows/NTFS
+            ident = ident.replaceAll("[^a-zA-Z0-9]", "");
+            ident = ident.replaceAll("[acegikmoqsuwy]", "");
+            return ident.substring(ident.length() - 70);
+        }
     }
 
     private File getPath(String ident) {
-        return new File(dir, clean(ident) + ".png");
+        return new File(dir, getUniqueFilename(ident) + ".png");
     }
 }
\ No newline at end of file
