Index: WMSLayer.java
===================================================================
--- WMSLayer.java	(revision 17300)
+++ WMSLayer.java	(working copy)
@@ -34,12 +34,14 @@
 import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
 import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
 import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.io.CacheFiles;
 import org.openstreetmap.josm.tools.ImageProvider;
 
 /**
  * This is a layer that grabs the current screen from an WMS server. The data
- * fetched this way is tiled and managerd to the disc to reduce server load.
+ * fetched this way is tiled and managed to the disc to reduce server load.
  */
+@SuppressWarnings("serial")
 public class WMSLayer extends Layer {
 	protected static final Icon icon =
 		new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms_small.png")));
@@ -70,33 +72,40 @@
 		mv = Main.map.mapView;
 	}
 
-	public WMSLayer(String name, String baseURL, String cookies) {
-		super(name);
-		alphaChannel.setSelected(Main.pref.getBoolean("wmsplugin.alpha_channel"));
-		background = true; /* set global background variable */
-		initializeImages();
-		this.baseURL = baseURL;
-		this.cookies = cookies;
-		WMSGrabber.getProjection(baseURL, true);
-		mv = Main.map.mapView;
-		resolution = mv.getDist100PixelText();
-		pixelPerDegree = getPPD();
+    public WMSLayer(String name, String baseURL, String cookies) {
+        super(name);
+        alphaChannel.setSelected(Main.pref.getBoolean("wmsplugin.alpha_channel"));
+        background = true; /* set global background variable */
+        initializeImages();
+        this.baseURL = baseURL;
+        this.cookies = cookies;
+        WMSGrabber.getProjection(baseURL, true);
+        mv = Main.map.mapView;
+        
+    	// quick hack to predefine the PixelDensity to reuse the cache
+    	int codeIndex = getName().indexOf("#PPD=");
+    	if (codeIndex != -1) {
+    		pixelPerDegree = Double.valueOf(getName().substring(codeIndex+5));
+    	} else {
+    		pixelPerDegree = getPPD();
+    	}
 
+    	resolution = "PixelPerDegree: " + Double.toString(pixelPerDegree) + " (add #PPD= to layer name to restore)";
 		executor = Executors.newFixedThreadPool(3);
 	}
 
-	@Override
-	public void destroy() {
-		try {
-			executor.shutdown();
-			// Might not be initalized, so catch NullPointer as well
-		} catch(Exception x) {}
-	}
+    @Override
+    public void destroy() {
+        try {
+            executor.shutdown();
+            // Might not be initialized, so catch NullPointer as well
+        } catch(Exception x) {}
+    }
 
-	public double getPPD(){
-		ProjectionBounds bounds = mv.getProjectionBounds();
-		return mv.getWidth() / (bounds.max.east() - bounds.min.east());
-	}
+    public double getPPD(){
+        ProjectionBounds bounds = mv.getProjectionBounds();
+        return mv.getWidth() / (bounds.max.east() - bounds.min.east());
+    }
 
 	public void initializeImages() {
 		images = new GeorefImage[dax][day];
@@ -200,23 +209,24 @@
 		return getToolTipText();
 	}
 
-	@Override public Component[] getMenuEntries() {
-		return new Component[]{
-				new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)),
-				new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)),
-				new JSeparator(),
-				new JMenuItem(new LoadWmsAction()),
-				new JMenuItem(new SaveWmsAction()),
-				new JSeparator(),
-				startstop,
-				alphaChannel,
-				new JMenuItem(new changeResolutionAction()),
-				new JMenuItem(new reloadErrorTilesAction()),
-				new JMenuItem(new downloadAction()),
-				new JSeparator(),
-				new JMenuItem(new LayerListPopup.InfoAction(this))
-		};
-	}
+    @Override public Component[] getMenuEntries() {
+        return new Component[]{
+                new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)),
+                new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)),
+                new JSeparator(),
+                new JMenuItem(new LoadWmsAction()),
+                new JMenuItem(new SaveWmsAction()),
+                new JMenuItem(new BookmarkWmsAction()),
+                new JSeparator(),
+                startstop,
+                alphaChannel,
+                new JMenuItem(new changeResolutionAction()),
+                new JMenuItem(new reloadErrorTilesAction()),
+                new JMenuItem(new downloadAction()),
+                new JSeparator(),
+                new JMenuItem(new LayerListPopup.InfoAction(this))
+        };
+    }
 
 	public GeorefImage findImage(EastNorth eastNorth) {
 		for(int x = 0; x<dax; ++x) {
@@ -250,13 +260,13 @@
 	}
 
 	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
-			WMSPlugin.cache.customCleanUp(WMSPlugin.cache.CLEAN_SMALL_FILES, 2048);
+        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
+            WMSPlugin.cache.customCleanUp(CacheFiles.CLEAN_SMALL_FILES, 4096);
 
 			for (int x = 0; x < dax; ++x) {
 				for (int y = 0; y < day; ++y) {
@@ -364,4 +374,35 @@
 			}
 		}
 	}
+    
+    /**
+     * This action will add a WMS layer menu entry with the current WMS layer URL and name extended by the current resolution.
+     * When using the menu entry again, the WMS cache will be used properly.
+     * 
+     * @author <alex@addismap.com>
+     */
+	public class BookmarkWmsAction extends AbstractAction {
+        public BookmarkWmsAction() {
+            super(tr("Set WMS Bookmark"));
+        }
+        public void actionPerformed(ActionEvent ev) {
+        	int i = 0;
+        	while (Main.pref.hasKey("wmsplugin.url."+i+".url")) {
+        		i++;
+        	}
+        	String baseName;
+        	// cut old parameter
+        	int parameterIndex = getName().indexOf("#PPD=");
+        	if (parameterIndex != -1) {
+        		baseName = getName().substring(0,parameterIndex);
+        	}
+        	else {
+        		baseName = getName();
+        	}
+        	Main.pref.put("wmsplugin.url."+ i +".url",baseURL );
+        	Main.pref.put("wmsplugin.url."+String.valueOf(i)+".name", baseName + "#" + getPPD() );
+        	WMSPlugin.refreshMenu();
+        }
+    }
+
 }
