Small reorganization

This commit is contained in:
krateng 2022-02-18 08:05:23 +01:00
parent 42607cedb7
commit e980efa731
1 changed files with 5 additions and 1 deletions

View File

@ -16,6 +16,8 @@ HIGH_NUMBER = 1000000
cache = lru.LRU(HIGH_NUMBER)
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}")
@ -24,11 +26,12 @@ def print_stats():
def cached_wrapper(inner_func):
if not USE_CACHE: return inner_func
def outer_func(**kwargs):
global hits, misses
key = (serialize(kwargs), inner_func, kwargs.get("since"), kwargs.get("to"))
if USE_CACHE and key in cache:
if key in cache:
hits += 1
return cache.get(key)
@ -60,6 +63,7 @@ def trim_cache():
log(f"New RAM usage: {psutil.virtual_memory().percent}%")
def serialize(obj):
try:
return serialize(obj.hashable())