From d0252554c40c843da37506405e31d38b16103c20 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Tue, 3 Sep 2024 18:23:41 +0200 Subject: [PATCH] Make extra sure cache is emptied when objects get altered. See the (new) cachePerInstance decorator in UM/Decorators, and the accompanying CachedMemberFunction handler-class. part of CURA-11761 --- cura/Settings/CuraContainerStack.py | 3 ++- cura/Settings/ExtruderStack.py | 3 ++- plugins/XmlMaterialProfile/XmlMaterialProfile.py | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cura/Settings/CuraContainerStack.py b/cura/Settings/CuraContainerStack.py index b5b8a1b721..ef1c9561af 100755 --- a/cura/Settings/CuraContainerStack.py +++ b/cura/Settings/CuraContainerStack.py @@ -5,7 +5,7 @@ from typing import Any, cast, List, Optional, Dict from PyQt6.QtCore import pyqtProperty, pyqtSignal, QObject from UM.Application import Application -from UM.Decorators import override +from UM.Decorators import CachedMemberFunctions, override from UM.FlameProfiler import pyqtSlot from UM.Logger import Logger from UM.Settings.ContainerStack import ContainerStack, InvalidContainerStackError @@ -237,6 +237,7 @@ class CuraContainerStack(ContainerStack): :param new_value: The new value to set the property to. """ + CachedMemberFunctions.clearInstanceCache(self) container_index = _ContainerIndexes.UserChanges self._containers[container_index].setProperty(key, property_name, property_value, container, set_from_cache) diff --git a/cura/Settings/ExtruderStack.py b/cura/Settings/ExtruderStack.py index eba41569b7..645abeb0f6 100644 --- a/cura/Settings/ExtruderStack.py +++ b/cura/Settings/ExtruderStack.py @@ -5,7 +5,7 @@ from typing import Any, Dict, TYPE_CHECKING, Optional from PyQt6.QtCore import pyqtProperty, pyqtSignal -from UM.Decorators import override +from UM.Decorators import CachedMemberFunctions, override from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase from UM.Settings.ContainerStack import ContainerStack from UM.Settings.ContainerRegistry import ContainerRegistry @@ -86,6 +86,7 @@ class ExtruderStack(CuraContainerStack): def setCompatibleMaterialDiameter(self, value: float) -> None: old_approximate_diameter = self.getApproximateMaterialDiameter() if self.getCompatibleMaterialDiameter() != value: + CachedMemberFunctions.clearInstanceCache(self) self.definitionChanges.setProperty("material_diameter", "value", value) self.compatibleMaterialDiameterChanged.emit() diff --git a/plugins/XmlMaterialProfile/XmlMaterialProfile.py b/plugins/XmlMaterialProfile/XmlMaterialProfile.py index 49b5e7661d..c56c527f92 100644 --- a/plugins/XmlMaterialProfile/XmlMaterialProfile.py +++ b/plugins/XmlMaterialProfile/XmlMaterialProfile.py @@ -11,6 +11,7 @@ import xml.etree.ElementTree as ET from UM.PluginRegistry import PluginRegistry from UM.Resources import Resources from UM.Logger import Logger +from UM.Decorators import CachedMemberFunctions import UM.Dictionary from UM.Settings.InstanceContainer import InstanceContainer from UM.Settings.ContainerRegistry import ContainerRegistry @@ -71,6 +72,8 @@ class XmlMaterialProfile(InstanceContainer): Logger.log("w", "Can't change metadata {key} of material {material_id} because it's read-only.".format(key = key, material_id = self.getId())) return + CachedMemberFunctions.clearInstanceCache(self) + # Some metadata such as diameter should also be instantiated to be a setting. Go though all values for the # "properties" field and apply the new values to SettingInstances as well. new_setting_values_dict = {} @@ -480,6 +483,7 @@ class XmlMaterialProfile(InstanceContainer): first.append(element) def clearData(self): + CachedMemberFunctions.clearInstanceCache(self) self._metadata = { "id": self.getId(), "name": "" @@ -519,6 +523,8 @@ class XmlMaterialProfile(InstanceContainer): def deserialize(self, serialized, file_name = None): """Overridden from InstanceContainer""" + CachedMemberFunctions.clearInstanceCache(self) + containers_to_add = [] # update the serialized data first from UM.Settings.Interfaces import ContainerInterface