osclib/cache: provide mechanism to init multiple times.

Useful for staging plugin to cache the remote config before StagingAPI
is initialized.
This commit is contained in:
Jimmy Berry 2018-09-04 15:04:04 -05:00
parent c47bb4c902
commit 3b8ae3174c
2 changed files with 8 additions and 0 deletions

View File

@ -389,6 +389,9 @@ def do_staging(self, subcmd, opts, *args):
else: else:
opts.project = 'Factory' opts.project = 'Factory'
# Cache the remote config fetch.
Cache.init()
# Init the OBS access and configuration # Init the OBS access and configuration
opts.project = self._full_project_name(opts.project) opts.project = self._full_project_name(opts.project)
opts.apiurl = self.get_api_url() opts.apiurl = self.get_api_url()

View File

@ -103,6 +103,11 @@ class Cache(object):
@staticmethod @staticmethod
def init(directory='main'): def init(directory='main'):
if Cache.CACHE_DIR:
# Stick with the first initialization to allow for StagingAPI to
# ensure always enabled, but allow parent to change directory.
return
Cache.CACHE_DIR = CacheManager.directory('request', directory) Cache.CACHE_DIR = CacheManager.directory('request', directory)
Cache.patterns = [] Cache.patterns = []