Small refactor

This commit is contained in:
krateng 2022-02-20 04:03:21 +01:00
parent bde06deb4f
commit 0f473599a7
1 changed files with 6 additions and 2 deletions

View File

@ -19,10 +19,13 @@ hits, misses = 0, 0
@runhourly
def print_stats():
log(f"Cache Size: {len(cache)}, RAM Utilization: {psutil.virtual_memory().percent}%, Cache Hits: {hits}/{hits+misses}")
def maintenance():
print_stats()
trim_cache()
def print_stats():
log(f"Cache Size: {len(cache)}, System RAM Utilization: {psutil.virtual_memory().percent}%, Cache Hits: {hits}/{hits+misses}")
def cached_wrapper(inner_func):
@ -48,6 +51,7 @@ def cached_wrapper(inner_func):
def invalidate_caches(scrobbletime):
cleared, kept = 0, 0
for k in cache.keys():
# VERY BIG TODO: differentiate between None as in 'unlimited timerange' and None as in 'time doesnt matter here'!
if (k[3] is None or scrobbletime >= k[3]) and (k[4] is None or scrobbletime <= k[4]):
cleared += 1
del cache[k]