From 2b837c887da2fce8b93010edd853f6fd7512bb2d Mon Sep 17 00:00:00 2001 From: southerntofu Date: Thu, 29 Jul 2021 11:06:27 -0400 Subject: [PATCH] Cache accepts arbitrary (lambda) condition for refreshing --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 670189a..1101081 100644 --- a/main.py +++ b/main.py @@ -67,15 +67,16 @@ class VideoWrapper: # Helper Class for using caches class Cache: - def __init__(self): + def __init__(self, criteria = lambda diff: diff.days > 0): self.dict = {} + self.criteria = criteria def get(self, arg, func): if arg in self.dict: last_time_updated = (self.dict[arg])[1] time_diff = datetime.now() - last_time_updated - if time_diff.days > 0: + if self.criteria(time_diff): self.dict[arg] = [ func(arg), datetime.now()