From af2fde75793fc33a8b08c7d05e67ebb5e4c8275c Mon Sep 17 00:00:00 2001 From: Ofer Koren Date: Mon, 3 Sep 2018 00:51:24 +0300 Subject: [PATCH] caching: use timecache around PersistentCache This is mainly for now where we disable it in our automation due to some unresolved bugs. When those are resolved we can turn it back on, although it is mainly for the benefit of users, not the volatile automation env. --- easypy/caching.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/easypy/caching.py b/easypy/caching.py index 122c8a3f..8a9a51e2 100644 --- a/easypy/caching.py +++ b/easypy/caching.py @@ -141,12 +141,17 @@ def inner(*args, **kwargs): ret = func(*args, **kwargs) self.set(key, ret) return ret + + inner = timecache(expiration=self.expiration)(inner) + self._timecache_clear = inner.cache_clear + inner.clear_cache = self.clear return inner def clear(self): with self.db_opened() as db: db.clear() + self._timecache_clear() def locking_lru_cache(maxsize=128, typed=False): # can't implement ignored_keywords because we use python's lru_cache... @@ -247,7 +252,7 @@ def inner(*args, **kwargs): with key_lock: result, ts = cache.get(key, NOT_CACHED) - if expiration <= 0: + if expiration is None or expiration <= 0: pass # nothing to fuss with, cache does not expire elif result is NOT_FOUND: pass # cache is empty