diff options
author | Raildo Mascena <rmascena@redhat.com> | 2018-06-26 13:13:30 -0300 |
---|---|---|
committer | Raildo Mascena <rmascena@redhat.com> | 2018-07-17 23:54:56 +0000 |
commit | ce150b10378aaf4f8b140a20a627b89c384c8867 (patch) | |
tree | 972e80f72f209b290e4222739c157274f9780013 | |
parent | b79f763b49557bf9d7f4fa595489f8c835f55da9 (diff) | |
download | oslo-config-ce150b10378aaf4f8b140a20a627b89c384c8867.tar.gz |
New cache layer for external sources6.4.0
Add a separate cache for values coming from external sources,
this will protect us from having options from external sources
mutated when we reload the configuration files
Change-Id: Icf72f4e1745a0ddf53e661cc08d0fe7428cd9a41
Blueprint: oslo-config-drivers
-rw-r--r-- | oslo_config/cfg.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/oslo_config/cfg.py b/oslo_config/cfg.py index f892f86..e42e52e 100644 --- a/oslo_config/cfg.py +++ b/oslo_config/cfg.py @@ -2408,6 +2408,7 @@ class ConfigOpts(collections.Mapping): self._mutable_ns = None self._mutate_hooks = set([]) self.__cache = {} + self.__drivers_cache = {} self._config_opts = [] self._cli_opts = collections.deque() self._validate_default_values = False @@ -2501,6 +2502,18 @@ class ConfigOpts(collections.Mapping): return __inner + def __clear_drivers_cache(f): + @functools.wraps(f) + def __inner(self, *args, **kwargs): + if kwargs.pop('clear_drivers_cache', True): + result = f(self, *args, **kwargs) + self.__drivers_cache.clear() + return result + else: + return f(self, *args, **kwargs) + + return __inner + def __call__(self, args=None, project=None, @@ -3105,10 +3118,18 @@ class ConfigOpts(collections.Mapping): "Value for option %s is not valid: %s" % (opt.name, str(ve))) + key = (group_name, name) + try: + return self.__drivers_cache[key] + except KeyError: # nosec: Valid control flow instruction + pass + for source in self._sources: val = source.get(group_name, name, opt) if val[0] != sources._NoValue: - return (convert(val[0]), val[1]) + result = (convert(val[0]), val[1]) + self.__drivers_cache[key] = result + return result if 'default' in info: return (self._substitute(info['default']), loc) @@ -3358,6 +3379,7 @@ class ConfigOpts(collections.Mapping): return namespace @__clear_cache + @__clear_drivers_cache def reload_config_files(self): """Reload configure files and parse all options |