Skip to content

Commit

Permalink
Merge pull request #19611 from Ultimaker/CURA-11761_container_stack_c…
Browse files Browse the repository at this point in the history
…ache

[CURA-11761] Make extra sure cache is emptied when objects get altered.
  • Loading branch information
HellAholic authored Sep 20, 2024
2 parents 494e61a + 69a9ff8 commit 424ae41
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cura/Settings/CuraContainerStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
Expand Down Expand Up @@ -237,6 +237,7 @@ def setProperty(self, key: str, property_name: str, property_value: Any, contain
: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)

Expand Down
3 changes: 2 additions & 1 deletion cura/Settings/ExtruderStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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
Expand Down Expand Up @@ -86,6 +86,7 @@ def getCompatibleMaterialDiameter(self) -> float:
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()

Expand Down
6 changes: 6 additions & 0 deletions plugins/XmlMaterialProfile/XmlMaterialProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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
Expand Down Expand Up @@ -71,6 +72,8 @@ def setMetaDataEntry(self, key, value, apply_to_all = True):
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 = {}
Expand Down Expand Up @@ -480,6 +483,7 @@ def _combineElement(first, second):
first.append(element)

def clearData(self):
CachedMemberFunctions.clearInstanceCache(self)
self._metadata = {
"id": self.getId(),
"name": ""
Expand Down Expand Up @@ -519,6 +523,8 @@ def getMetadataFromSerialized(cls, serialized: str, property_name: str) -> str:
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
Expand Down

0 comments on commit 424ae41

Please sign in to comment.