From 42671f9764c7e558a502263282c074cedd3bc5f4 Mon Sep 17 00:00:00 2001 From: Felipe Martin Date: Wed, 8 Jan 2014 13:40:32 +0100 Subject: [PATCH] Backups use/store cache based on the data variable cache.enabled --- iosfu/plugin/base.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/iosfu/plugin/base.py b/iosfu/plugin/base.py index 14177fb..25a76cb 100644 --- a/iosfu/plugin/base.py +++ b/iosfu/plugin/base.py @@ -39,14 +39,23 @@ class BasePlugin(object): Main function called by plugin library. """ if self._backup: - cached = self._backup.cache(self.__slug__) - if cached is None: - result = self.__do__(*args, **kwargs) + + # Load from cache if enabled + if self._backup.data('cache.enabled'): + cached = self._backup.cache(self.__slug__) + if cached is not None: + return cached + + # Not found in cache, execute plugin! + result = self.__do__(*args, **kwargs) + + # Save to cache if enabled + if self._backup.data('cache.enabled'): self._backup.cache(self.__slug__, result) self._backup.write_data_file() - return result - else: - return cached + + # Return result + return result else: raise Exception( 'Plugin {0} need a backup instance to work with'.format(