Cleanup cache when a component is deleted from the project

This commit is contained in:
Bane Stojkovic
2022-07-05 09:26:45 +02:00
parent 8d385ef812
commit a08c8a4484
3 changed files with 14 additions and 1 deletions
@@ -23,6 +23,7 @@ import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.lang.ref.SoftReference;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
@@ -163,6 +164,12 @@ public class DrawingCache {
imageCache.clear();
}
public void invalidate(Collection<IDIYComponent<?>> components) {
for (IDIYComponent<?> component : components) {
imageCache.remove(component);
}
}
private CacheValue renderAndCache(IDIYComponent<?> component, G2DWrapper g2d, ComponentState componentState,
boolean outlineMode, Project project, double zoom) {
// if we need to apply caching
@@ -1772,6 +1772,8 @@ public class Presenter implements IPlugInPort {
drawingManager.clearContinuityArea();
currentProject.getComponents().removeAll(selectedComponents);
DrawingCache.Instance.invalidate(selectedComponents);
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(), "Delete");
drawingManager.clearContinuityArea();
projectFileManager.notifyFileChange();
@@ -3864,7 +3864,11 @@
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Limit memory usage to avoid out of memory errors when 'Cache Boost' feature is enabled</description>
<description>Limit memory usage to avoid out of memory errors when 'Cache Boost' feature is enabled on complex project</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Cleanup cache when a component is deleted from the project</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>