Index: wmsplugin/src/wmsplugin/Grabber.java
===================================================================
--- wmsplugin/src/wmsplugin/Grabber.java	(revision 15114)
+++ wmsplugin/src/wmsplugin/Grabber.java	(working copy)
@@ -2,16 +2,17 @@
 
 import static org.openstreetmap.josm.tools.I18n.tr;
 
+import java.awt.image.BufferedImage;
+import java.awt.Graphics;
+import java.awt.Color;
+import java.awt.Font;
+
 import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.projection.Projection;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.Main;
-import java.awt.image.BufferedImage;
-import java.awt.Graphics;
-import java.awt.Color;
-import java.awt.Font;
-import javax.swing.JOptionPane;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.io.CacheFiles;
 
 abstract public class Grabber implements Runnable {
     protected Bounds b;
@@ -20,9 +21,10 @@
     protected MapView mv;
     protected WMSLayer layer;
     protected GeorefImage image;
+    protected CacheFiles cache;
 
     Grabber(Bounds b, Projection proj, double pixelPerDegree, GeorefImage image,
-    MapView mv, WMSLayer layer)
+    MapView mv, WMSLayer layer, CacheFiles cache)
     {
         if (b.min != null && b.max != null && WMSPlugin.doOverlap)
         {
@@ -48,6 +50,7 @@
         this.image = image;
         this.mv = mv;
         this.layer = layer;
+        this.cache = cache;
     }
 
     abstract void fetch() throws Exception; // the image fetch code
Index: wmsplugin/src/wmsplugin/WMSGrabber.java
===================================================================
--- wmsplugin/src/wmsplugin/WMSGrabber.java	(revision 15114)
+++ wmsplugin/src/wmsplugin/WMSGrabber.java	(working copy)
@@ -27,18 +27,18 @@
 import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.projection.Projection;
 import org.openstreetmap.josm.gui.MapView;
+import org.openstreetmap.josm.io.CacheFiles;
 import org.openstreetmap.josm.io.ProgressInputStream;
 
 
 public class WMSGrabber extends Grabber {
     protected String baseURL;
-    protected Cache cache = new wmsplugin.Cache();
     private static Boolean shownWarning = false;
     private boolean urlWithPatterns;
 
     WMSGrabber(String baseURL, Bounds b, Projection proj,
-            double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) {
-        super(b, proj, pixelPerDegree, image, mv, layer);
+            double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
+        super(b, proj, pixelPerDegree, image, mv, layer, cache);
         this.baseURL = baseURL;
         /* URL containing placeholders? */
         urlWithPatterns = baseURL != null && baseURL.contains("{1}");
@@ -146,7 +146,8 @@
         BufferedImage img = ImageIO.read(is);
         is.close();
         
-        return cache.saveImg(url.toString(), img, true);
+        cache.saveImg(url.toString(), img);
+        return img;
     }
 
     protected String readException(URLConnection conn) throws IOException {
Index: wmsplugin/src/wmsplugin/WMSLayer.java
===================================================================
--- wmsplugin/src/wmsplugin/WMSLayer.java	(revision 15114)
+++ wmsplugin/src/wmsplugin/WMSLayer.java	(working copy)
@@ -254,7 +254,7 @@
         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);
+            WMSPlugin.cache.customCleanUp(WMSPlugin.cache.CLEAN_SMALL_FILES, 2048);
 
             for (int x = 0; x < dax; ++x) {
                 for (int y = 0; y < day; ++y) {
Index: wmsplugin/src/wmsplugin/WMSPlugin.java
===================================================================
--- wmsplugin/src/wmsplugin/WMSPlugin.java	(revision 15114)
+++ wmsplugin/src/wmsplugin/WMSPlugin.java	(working copy)
@@ -23,6 +23,7 @@
 import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.gui.IconToggleButton;
 import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
+import org.openstreetmap.josm.io.CacheFiles;
 import org.openstreetmap.josm.io.MirroredInputStream;
 import org.openstreetmap.josm.actions.JosmAction;
 import org.openstreetmap.josm.data.Bounds;
@@ -30,6 +31,7 @@
 import org.openstreetmap.josm.gui.MapView;
 
 public class WMSPlugin extends Plugin {
+    static CacheFiles cache = new CacheFiles("wmsplugin");
 
     WMSLayer wmsLayer;
     static JMenu wmsJMenu;
@@ -53,6 +55,8 @@
             e.printStackTrace();
         }
         refreshMenu();
+        cache.setExpire(cache.EXPIRE_MONTHLY, false);
+        cache.setMaxSize(70, false);
     }
 
     // this parses the preferences settings. preferences for the wms plugin have to
@@ -198,9 +202,9 @@
     public static Grabber getGrabber(String _baseURL, Bounds _b, Projection _proj,
                      double _pixelPerDegree, GeorefImage _image, MapView _mv, WMSLayer _layer){
         if(_baseURL.startsWith("yahoo://"))
-            return new YAHOOGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer);
+            return new YAHOOGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer, cache);
         else
-            return new WMSGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer);
+            return new WMSGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer, cache);
         // OSBGrabber should be rewrite for thread support first
         //if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ){
         //  return new OSGBGrabber(_b, _proj, _pixelPerDegree,  _images, _mv, _layer);
Index: wmsplugin/src/wmsplugin/YAHOOGrabber.java
===================================================================
--- wmsplugin/src/wmsplugin/YAHOOGrabber.java	(revision 15114)
+++ wmsplugin/src/wmsplugin/YAHOOGrabber.java	(working copy)
@@ -15,17 +15,17 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.projection.Projection;
+import org.openstreetmap.josm.io.CacheFiles;
 import org.openstreetmap.josm.gui.MapView;
 
 
-public class YAHOOGrabber extends WMSGrabber{
+public class YAHOOGrabber extends WMSGrabber {
     protected String browserCmd;
-    protected Cache cache = new wmsplugin.Cache();
 
     YAHOOGrabber(String baseURL, Bounds b, Projection proj,
-            double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) {
+            double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
         super("file:///" + WMSPlugin.getPrefsPath() + "ymap.html?"
-        , b, proj, pixelPerDegree, image, mv, layer);
+        , b, proj, pixelPerDegree, image, mv, layer, cache);
         this.browserCmd = baseURL.replaceFirst("yahoo://", "");
     }
 
@@ -52,7 +52,9 @@
         } catch(IOException ioe) {
             throw new IOException( "Could not start browser. Please check that the executable path is correct.\n" + ioe.getMessage() );
         }
-
-        return cache.saveImg(urlstring, ImageIO.read(browser.getInputStream()), true);
+        
+        BufferedImage img = ImageIO.read(browser.getInputStream());
+        cache.saveImg(urlstring, img);
+        return img;
     }
 }
