Index: trunk/src/org/openstreetmap/josm/command/PurgeCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/PurgeCommand.java	(revision 13419)
+++ trunk/src/org/openstreetmap/josm/command/PurgeCommand.java	(revision 13420)
@@ -115,4 +115,5 @@
                 }
             }
+            getAffectedDataSet().clearMappaintCache();
         } finally {
             getAffectedDataSet().endUpdate();
@@ -126,20 +127,26 @@
             return;
 
-        for (OsmPrimitive osm : toPurge) {
-            PrimitiveData data = makeIncompleteDataByPrimId.get(osm);
-            if (data != null) {
-                if (getAffectedDataSet().getPrimitiveById(osm) != osm)
-                    throw new AssertionError(
-                            String.format("Primitive %s has been made incomplete when purging, but it cannot be found on undo.", osm));
-                osm.load(data);
-            } else {
-                if (getAffectedDataSet().getPrimitiveById(osm) != null)
-                    throw new AssertionError(String.format("Primitive %s was removed when purging, but is still there on undo", osm));
-                getAffectedDataSet().addPrimitive(osm);
-            }
-        }
-
-        for (Conflict<?> conflict : purgedConflicts) {
-            getAffectedDataSet().getConflicts().add(conflict);
+        getAffectedDataSet().beginUpdate();
+        try {
+            for (OsmPrimitive osm : toPurge) {
+                PrimitiveData data = makeIncompleteDataByPrimId.get(osm);
+                if (data != null) {
+                    if (getAffectedDataSet().getPrimitiveById(osm) != osm)
+                        throw new AssertionError(
+                                String.format("Primitive %s has been made incomplete when purging, but it cannot be found on undo.", osm));
+                    osm.load(data);
+                } else {
+                    if (getAffectedDataSet().getPrimitiveById(osm) != null)
+                        throw new AssertionError(String.format("Primitive %s was removed when purging, but is still there on undo", osm));
+                    getAffectedDataSet().addPrimitive(osm);
+                }
+            }
+
+            for (Conflict<?> conflict : purgedConflicts) {
+                getAffectedDataSet().getConflicts().add(conflict);
+            }
+            getAffectedDataSet().clearMappaintCache();
+        } finally {
+            getAffectedDataSet().endUpdate();
         }
     }
Index: trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 13419)
+++ trunk/src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 13420)
@@ -200,4 +200,6 @@
     private final ConflictCollection conflicts = new ConflictCollection();
 
+    private short mappaintCacheIdx = 1;
+
     /**
      * Constructs a new {@code DataSet}.
@@ -1380,3 +1382,23 @@
         return null;
     }
+
+    /**
+     * Returns mappaint cache index for this DataSet.
+     *
+     * If the {@link OsmPrimitive#mappaintCacheIdx} is not equal to the DataSet mappaint
+     * cache index, this means the cache for that primitive is out of date.
+     * @return mappaint cache index
+     * @since 13420
+     */
+    public short getMappaintCacheIndex() {
+        return mappaintCacheIdx;
+    }
+
+    /**
+     * Clear the mappaint cache for this DataSet.
+     * @since 13420
+     */
+    public void clearMappaintCache() {
+        mappaintCacheIdx++;
+    }
 }
Index: trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java	(revision 13419)
+++ trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java	(revision 13420)
@@ -204,7 +204,26 @@
 
     /**
+     * Check if the cached style for this primitive is up to date.
+     * @return true if the cached style for this primitive is up to date
+     * @since 13420
+     */
+    public final boolean isCachedStyleUpToDate() {
+        return mappaintStyle != null && mappaintCacheIdx == dataSet.getMappaintCacheIndex();
+    }
+
+    /**
+     * Declare that the cached style for this primitive is up to date.
+     * @since 13420
+     */
+    public final void declareCachedStyleUpToDate() {
+        this.mappaintCacheIdx = dataSet.getMappaintCacheIndex();
+    }
+
+    /**
      * Returns mappaint cache index.
      * @return mappaint cache index
-     */
+     * @deprecated no longer supported (see also {@link #isCachedStyleUpToDate()})
+     */
+    @Deprecated
     public final short getMappaintCacheIdx() {
         return mappaintCacheIdx;
@@ -214,5 +233,7 @@
      * Sets the mappaint cache index.
      * @param mappaintCacheIdx mappaint cache index
-     */
+     * @deprecated no longer supported (see also {@link #declareCachedStyleUpToDate()})
+     */
+    @Deprecated
     public final void setMappaintCacheIdx(short mappaintCacheIdx) {
         this.mappaintCacheIdx = mappaintCacheIdx;
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java	(revision 13419)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java	(revision 13420)
@@ -19,5 +19,7 @@
 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon;
 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.NavigatableComponent;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.gui.mappaint.DividedScale.RangeViolatedError;
 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
@@ -90,4 +92,6 @@
             preferenceCache.clear();
             backgroundColorCache = null;
+            MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).forEach(
+                    dl -> dl.data.clearMappaintCache());
         });
     }
@@ -139,5 +143,5 @@
      */
     public Pair<StyleElementList, Range> getStyleCacheWithRange(OsmPrimitive osm, double scale, NavigatableComponent nc) {
-        if (osm.mappaintStyle == null || osm.getMappaintCacheIdx() != cacheIdx || scale <= 0) {
+        if (!osm.isCachedStyleUpToDate() || scale <= 0) {
             osm.mappaintStyle = StyleCache.EMPTY_STYLECACHE;
         } else {
@@ -195,5 +199,5 @@
                     + ", scale: " + scale + ", new stylelist: " + p.a + ", new range: " + p.b + ')', e);
         }
-        osm.setMappaintCacheIdx(cacheIdx);
+        osm.declareCachedStyleUpToDate();
         return p;
     }
