From 41d03be0632e81de6ae796581c1a10056adc50c4 Mon Sep 17 00:00:00 2001 From: Kent Ou <84220825+kentnsw@users.noreply.github.com> Date: Fri, 26 Aug 2022 10:04:16 +1000 Subject: [PATCH] cache - revert the haskey() customization --- c7n/cache.py | 16 ++++++---------- c7n/resolver.py | 4 +--- tests/test_resolver.py | 3 --- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/c7n/cache.py b/c7n/cache.py index 7e5dba26bac..086318f7afe 100644 --- a/c7n/cache.py +++ b/c7n/cache.py @@ -46,9 +46,6 @@ def load(self): def get(self, key): pass - def haskey(self, key): - pass - def save(self, key, data): pass @@ -85,9 +82,6 @@ def load(self): def get(self, key): return self.data.get(encode(key)) - def haskey(self, key): - return pickle.dumps(key) in self.data # nosemgrep - def save(self, key, data): self.data[encode(key)] = data @@ -121,10 +115,7 @@ def __init__(self, config): self.cache_path = resolve_path(config.cache) self.conn = None - def haskey(self, key): - return pickle.dumps(key) in self.data # nosemgrep - - def load(self): + def init(self): # migration from pickle cache file if os.path.exists(self.cache_path): with open(self.cache_path, 'rb') as fh: @@ -142,9 +133,14 @@ def load(self): cursor.execute( 'delete from c7n_cache where create_date < ?', [datetime.utcnow() - timedelta(minutes=self.cache_period)]) + + def load(self): + if not self.conn: + self.init() return True def get(self, key): + self.load() with self.conn as cursor: r = cursor.execute( 'select value, create_date from c7n_cache where key = ?', diff --git a/c7n/resolver.py b/c7n/resolver.py index c8334e65bd1..ad0cf362d99 100644 --- a/c7n/resolver.py +++ b/c7n/resolver.py @@ -156,9 +156,7 @@ def get_values(self): # the results. key = [self.data.get(i) for i in ('url', 'format', 'expr')] contents = self.cache.get(("value-from", key)) - # NOTE no matter the contents is None or not, return it - # if contents is not None: - if self.cache.haskey(("value-from", key)): + if contents is not None: return contents contents = self._get_values() diff --git a/tests/test_resolver.py b/tests/test_resolver.py index f88f2333f6c..924b4545c76 100644 --- a/tests/test_resolver.py +++ b/tests/test_resolver.py @@ -30,9 +30,6 @@ def save(self, key, data): self.saves += 1 self.state[pickle.dumps(key)] = data - def haskey(self, key): - return pickle.dumps(key) in self.state - class FakeResolver: