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:
parent
618c2f2931
commit
f1c2bca901
11
doors.py
11
doors.py
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue