mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Small reorganization
This commit is contained in:
@ -16,6 +16,8 @@ HIGH_NUMBER = 1000000
|
|||||||
cache = lru.LRU(HIGH_NUMBER)
|
cache = lru.LRU(HIGH_NUMBER)
|
||||||
hits, misses = 0, 0
|
hits, misses = 0, 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@runhourly
|
@runhourly
|
||||||
def print_stats():
|
def print_stats():
|
||||||
log(f"Cache Size: {len(cache)}, RAM Utilization: {psutil.virtual_memory().percent}%, Cache Hits: {hits}/{hits+misses}")
|
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):
|
def cached_wrapper(inner_func):
|
||||||
|
|
||||||
|
if not USE_CACHE: return inner_func
|
||||||
def outer_func(**kwargs):
|
def outer_func(**kwargs):
|
||||||
global hits, misses
|
global hits, misses
|
||||||
key = (serialize(kwargs), inner_func, kwargs.get("since"), kwargs.get("to"))
|
key = (serialize(kwargs), inner_func, kwargs.get("since"), kwargs.get("to"))
|
||||||
|
|
||||||
if USE_CACHE and key in cache:
|
if key in cache:
|
||||||
hits += 1
|
hits += 1
|
||||||
return cache.get(key)
|
return cache.get(key)
|
||||||
|
|
||||||
@ -60,6 +63,7 @@ def trim_cache():
|
|||||||
log(f"New RAM usage: {psutil.virtual_memory().percent}%")
|
log(f"New RAM usage: {psutil.virtual_memory().percent}%")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def serialize(obj):
|
def serialize(obj):
|
||||||
try:
|
try:
|
||||||
return serialize(obj.hashable())
|
return serialize(obj.hashable())
|
||||||
|
Reference in New Issue
Block a user