Periodically clear the key cache

Clear the cache on the first scan of each month.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
Anna Schumaker 2016-01-12 10:51:48 -05:00
parent 618c2f2931
commit f1c2bca901
1 changed files with 11 additions and 0 deletions

View File

@ -94,6 +94,7 @@ def blink_leds():
import time import time
import datetime
from urllib import request from urllib import request
############################################# #############################################
# # # #
@ -102,6 +103,7 @@ from urllib import request
############################################# #############################################
CACHED_KEYS = set() CACHED_KEYS = set()
NEED_PING = [] NEED_PING = []
THIS_MONTH = datetime.date.today().month
def ping_server(key): def ping_server(key):
print("Pinging server with key: %s" % key) print("Pinging server with key: %s" % key)
@ -113,7 +115,16 @@ def ping_server(key):
CACHED_KEYS.remove(key) CACHED_KEYS.remove(key)
return False 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): def valid_key(key):
clear_cache()
if key in CACHED_KEYS: if key in CACHED_KEYS:
print("Using cached key") print("Using cached key")
NEED_PING.append(key) NEED_PING.append(key)