diff --git a/octoprint_DisplayLayerProgress/CachedSettings.py b/octoprint_DisplayLayerProgress/CachedSettings.py new file mode 100644 index 0000000..9922750 --- /dev/null +++ b/octoprint_DisplayLayerProgress/CachedSettings.py @@ -0,0 +1,57 @@ +# coding=utf-8 +from __future__ import absolute_import + + +class CachedSettings(): + + cacheEnabled = True + cacheDict = {} + + def __init__(self, pluginSettings): + self._pluginSettings = pluginSettings + + def updateSettings(self, pluginSettings): + self._pluginSettings = pluginSettings + self.cacheDict = {} + + + def getStringValue(self, settingsKey): + value = self._getValueFromCache(settingsKey) + if (value == None): + # try to read from real settings + value = self._pluginSettings.get([settingsKey]) + # add to cache if needed + if (value != None and self.cacheEnabled == True): + self.cacheDict[settingsKey] = value + + return value + + def getIntValue(self, settingsKey): + value = self._getValueFromCache(settingsKey) + if (value == None): + # try to read from real settings + value = self._pluginSettings.get_int([settingsKey]) + # add to cache if needed + if (value != None and self.cacheEnabled == True): + self.cacheDict[settingsKey] = value + + return value + + def getBooleanValue(self, settingsKey): + value = self._getValueFromCache(settingsKey) + if (value == None): + # try to read from real settings + value = self._pluginSettings.get_boolean([settingsKey]) + # add to cache if needed + if (value != None and self.cacheEnabled == True): + self.cacheDict[settingsKey] = value + + return value + + def _getValueFromCache(self, settingsKey): + value = None + if (self.cacheEnabled == True): + if (settingsKey in self.cacheDict): + value = self.cacheDict[settingsKey] + return value + diff --git a/setup.py b/setup.py index 5fe17c7..a183c00 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "DisplayLayerProgress" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.25.0" +plugin_version = "1.25.1" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module