Backups use/store cache based on the data variable cache.enabled

This commit is contained in:
Felipe Martin 2014-01-08 13:40:32 +01:00
parent 577b10273a
commit 42671f9764
1 changed files with 15 additions and 6 deletions

View File

@ -39,14 +39,23 @@ class BasePlugin(object):
Main function called by plugin library. Main function called by plugin library.
""" """
if self._backup: if self._backup:
cached = self._backup.cache(self.__slug__)
if cached is None: # Load from cache if enabled
result = self.__do__(*args, **kwargs) 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.cache(self.__slug__, result)
self._backup.write_data_file() self._backup.write_data_file()
return result
else: # Return result
return cached return result
else: else:
raise Exception( raise Exception(
'Plugin {0} need a backup instance to work with'.format( 'Plugin {0} need a backup instance to work with'.format(