From f1c2bca90166bbaad5f90c4da89fa986a79e4beb Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 12 Jan 2016 10:51:48 -0500 Subject: [PATCH] Periodically clear the key cache Clear the cache on the first scan of each month. Signed-off-by: Anna Schumaker --- doors.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doors.py b/doors.py index 2df5ae1..30b6a8d 100755 --- a/doors.py +++ b/doors.py @@ -94,6 +94,7 @@ def blink_leds(): import time +import datetime from urllib import request ############################################# # # @@ -102,6 +103,7 @@ from urllib import request ############################################# CACHED_KEYS = set() NEED_PING = [] +THIS_MONTH = datetime.date.today().month def ping_server(key): print("Pinging server with key: %s" % key) @@ -113,7 +115,16 @@ def ping_server(key): CACHED_KEYS.remove(key) return False +def clear_cache(): + global THIS_MONTH + + today = datetime.date.today() + if today.month != THIS_MONTH: + CACHED_KEYS.clear() + THIS_MONTH = today.month + def valid_key(key): + clear_cache() if key in CACHED_KEYS: print("Using cached key") NEED_PING.append(key)