From b894ecafb4ce162af80d3d85b9d7fee02d53ab65 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 15 Apr 2022 19:01:03 +0200 Subject: [PATCH] :sparkles: Allow config items cache to be cleared and refetched --- cfig/config.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/cfig/config.py b/cfig/config.py index 348a463..077072a 100644 --- a/cfig/config.py +++ b/cfig/config.py @@ -198,10 +198,24 @@ class Configuration: self.items[key] = item self.docs[key] = doc - def fetch_all(self): - log.debug("Fetching now all configuration items...") - for value in self.items.values(): - _ = value.__wrapped__ + def fetch_all(self, clear: bool = True): + """ + Fetch all configuration values. + + If values were fetched earlier, and the ``clear`` parameter is :data:`True`, + this will clear the cache and re-fetch them, possibly changing some items. + """ + + if clear: + log.debug("Clearing the cached items...") + for item in self.items.values(): + log.debug(f"Clearing: {item!r}") + del item.__wrapped__ + + log.debug("Fetching items...") + for item in self.items.values(): + log.debug(f"Fetching: {item!r}") + _ = item.__wrapped__ __all__ = (