Index: wmsplugin/src/wmsplugin/Cache.java
===================================================================
--- wmsplugin/src/wmsplugin/Cache.java	(revision 15089)
+++ wmsplugin/src/wmsplugin/Cache.java	(working copy)
@@ -7,6 +7,7 @@
 import java.security.MessageDigest;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.Random;
 import java.util.Set;
 import java.util.TreeMap;
 import javax.imageio.*;
@@ -23,6 +24,8 @@
     private boolean disabled = false;
     // If the cache is full, we don't want to delete just one file
     private final int cleanUpThreshold = 20;
+    // After how many file-writes do we want to check if the cache needs emptying?
+    private final int cleanUpInterval = 5;
 
     Cache() {
         this(Main.pref.get("wmsplugin.cache.path", WMSPlugin.getPrefsPath() + "cache"));
@@ -72,7 +75,7 @@
             System.out.println(e.getMessage());
         }
 
-        // Clean up must be called manually
+        checkCleanUp();
     }
 
     public BufferedImage saveImg(String ident, BufferedImage image, boolean passThrough) {
@@ -80,6 +83,13 @@
         return image;
     }
 
+    public void checkCleanUp() {
+        // The Cache class isn't persistent in its current implementation,
+        // therefore clean up on random intervals, but not every write
+        if(new Random().nextInt(cleanUpInterval) == 0)
+            cleanUp();
+    }
+
     public void cleanUp() {
         if(disabled) return;
 
@@ -111,7 +121,16 @@
         }
     }
 
+    public void deleteSmallFiles(int size) {
+        if(disabled) return;
+        for(File f : getFiles()) {
+            if(f.length() < size)
+                f.delete();
+        }
+    }
+
     private long getDirSize() {
+        if(disabled) return -1;
         long dirsize = 0;
 
         for(File f : getFiles())
@@ -120,6 +139,7 @@
     }
 
     private File[] getFiles() {
+        if(disabled) return null;
         return dir.listFiles(
             new FileFilter() {
                 public boolean accept(File file) {
Index: wmsplugin/src/wmsplugin/WMSLayer.java
===================================================================
--- wmsplugin/src/wmsplugin/WMSLayer.java	(revision 15089)
+++ wmsplugin/src/wmsplugin/WMSLayer.java	(working copy)
@@ -79,13 +79,13 @@
         WMSGrabber.getProjection(baseURL, true);
         mv = Main.map.mapView;
         getPPD();
-        
+
         executor = Executors.newFixedThreadPool(3);
     }
-    
+
     public void destroy() {
-        try { 
-            executor.shutdown();  
+        try {
+            executor.shutdown();
         // Might not be initalized, so catch NullPointer as well
         } catch(Exception x) {}
     }
@@ -171,7 +171,7 @@
             JOptionPane.showMessageDialog(Main.parent, tr("The requested area is too big. Please zoom in a little, or change resolution"));
             return;
         }
-        
+
         for(int x = bminx; x<bmaxx; ++x)
             for(int y = bminy; y<bmaxy; ++y){
                 GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
@@ -183,8 +183,6 @@
                     executor.submit(gr);
             }
         }
-
-        new wmsplugin.Cache().cleanUp();
     }
 
     @Override public void visitBoundingBox(BoundingXYVisitor v) {
@@ -247,12 +245,16 @@
             mv.repaint();
         }
     }
-    
+
     public class reloadErrorTilesAction extends AbstractAction {
         public reloadErrorTilesAction() {
             super(tr("Reload erroneous tiles"));
         }
         public void actionPerformed(ActionEvent ev) {
+            // Delete small files, because they're probably blank tiles.
+            // See https://josm.openstreetmap.de/ticket/2307
+            new wmsplugin.Cache().deleteSmallFiles(2048);
+
             for (int x = 0; x < dax; ++x) {
                 for (int y = 0; y < day; ++y) {
                     GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
@@ -265,7 +267,7 @@
             }
         }
     }
-    
+
     public class ToggleAlphaAction extends AbstractAction {
         public ToggleAlphaAction() {
             super(tr("Alpha channel"));
@@ -274,7 +276,7 @@
             JCheckBoxMenuItem checkbox = (JCheckBoxMenuItem) ev.getSource();
             boolean alphaChannel = checkbox.isSelected();
             Main.pref.put("wmsplugin.alpha_channel", alphaChannel);
-            
+
             // clear all resized cached instances and repaint the layer
             for (int x = 0; x < dax; ++x) {
                 for (int y = 0; y < day; ++y) {
