From 9b5e5ee01ed9676eca8482f89ac278f42c1ca2b9 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 27 Oct 2016 17:21:03 +0200 Subject: [PATCH] Include the version in the cached definitions path This ensures we do not try to load old cache files when a newer version is used, or the other way around. Fixes CURA-2832 --- UM/Application.py | 2 ++ UM/Settings/ContainerRegistry.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/UM/Application.py b/UM/Application.py index 1b64518ef6..951de7257a 100644 --- a/UM/Application.py +++ b/UM/Application.py @@ -105,6 +105,8 @@ def __init__(self, name, version, buildtype = "", **kwargs): self._plugin_registry.setApplication(self) + UM.Settings.ContainerRegistry.setApplication(self) + self._parsed_command_line = None self.parseCommandLine() diff --git a/UM/Settings/ContainerRegistry.py b/UM/Settings/ContainerRegistry.py index f28579dddb..df934b3103 100644 --- a/UM/Settings/ContainerRegistry.py +++ b/UM/Settings/ContainerRegistry.py @@ -454,7 +454,7 @@ def _deleteFiles(self, container): # Load a binary cached version of a DefinitionContainer def _loadCachedDefinition(self, definition_id, path): try: - cache_path = Resources.getPath(Resources.Cache, "definitions", definition_id) + cache_path = Resources.getPath(Resources.Cache, "definitions", self.getApplication().getVersion(), definition_id) cache_mtime = os.path.getmtime(cache_path) definition_mtime = os.path.getmtime(path) @@ -483,7 +483,7 @@ def _loadCachedDefinition(self, definition_id, path): # Store a cached version of a DefinitionContainer def _saveCachedDefinition(self, definition): - cache_path = Resources.getStoragePath(Resources.Cache, "definitions", definition.id) + cache_path = Resources.getStoragePath(Resources.Cache, "definitions", self.getApplication().getVersion(), definition.id) # Ensure the cache path exists os.makedirs(os.path.dirname(cache_path), exist_ok=True) @@ -499,6 +499,15 @@ def getInstance(cls): ContainerRegistry.__instance = cls() return ContainerRegistry.__instance + @classmethod + def setApplication(cls, application): + cls.__application = application + + @classmethod + def getApplication(cls): + return cls.__application + + __application = None __instance = None __container_types = {