mirror of
https://github.com/krateng/maloja.git
synced 2025-07-09 03:04:07 -04:00
Implemented cache enabling and disabling at runtime
This commit is contained in:
parent
279499ad9f
commit
7c77474feb
@ -10,10 +10,8 @@ from doreah.logging import log
|
|||||||
|
|
||||||
from ..pkg_global.conf import malojaconfig
|
from ..pkg_global.conf import malojaconfig
|
||||||
|
|
||||||
HIGH_NUMBER = 1000000
|
CACHE_SIZE = 1000
|
||||||
CACHE_SIZE = 10000
|
ENTITY_CACHE_SIZE = 100000
|
||||||
ENTITY_CACHE_SIZE = 1000000
|
|
||||||
CACHE_ADJUST_STEP = 100
|
|
||||||
|
|
||||||
cache = lru.LRU(CACHE_SIZE)
|
cache = lru.LRU(CACHE_SIZE)
|
||||||
entitycache = lru.LRU(ENTITY_CACHE_SIZE)
|
entitycache = lru.LRU(ENTITY_CACHE_SIZE)
|
||||||
@ -38,8 +36,10 @@ def print_stats():
|
|||||||
|
|
||||||
def cached_wrapper(inner_func):
|
def cached_wrapper(inner_func):
|
||||||
|
|
||||||
if not malojaconfig['USE_GLOBAL_CACHE']: return inner_func
|
|
||||||
def outer_func(*args,**kwargs):
|
def outer_func(*args,**kwargs):
|
||||||
|
if not malojaconfig['USE_GLOBAL_CACHE']: inner_func(*args,**kwargs)
|
||||||
|
|
||||||
if 'dbconn' in kwargs:
|
if 'dbconn' in kwargs:
|
||||||
conn = kwargs.pop('dbconn')
|
conn = kwargs.pop('dbconn')
|
||||||
else:
|
else:
|
||||||
@ -65,8 +65,9 @@ def cached_wrapper(inner_func):
|
|||||||
# cache that's aware of what we're calling
|
# cache that's aware of what we're calling
|
||||||
def cached_wrapper_individual(inner_func):
|
def cached_wrapper_individual(inner_func):
|
||||||
|
|
||||||
if not malojaconfig['USE_GLOBAL_CACHE']: return inner_func
|
|
||||||
def outer_func(set_arg,**kwargs):
|
def outer_func(set_arg,**kwargs):
|
||||||
|
if not malojaconfig['USE_GLOBAL_CACHE']: return inner_func(set_arg,**kwargs)
|
||||||
|
|
||||||
|
|
||||||
if 'dbconn' in kwargs:
|
if 'dbconn' in kwargs:
|
||||||
@ -95,16 +96,15 @@ def cached_wrapper_individual(inner_func):
|
|||||||
return outer_func
|
return outer_func
|
||||||
|
|
||||||
def invalidate_caches(scrobbletime=None):
|
def invalidate_caches(scrobbletime=None):
|
||||||
if malojaconfig['USE_GLOBAL_CACHE']:
|
cleared, kept = 0, 0
|
||||||
cleared, kept = 0, 0
|
for k in cache.keys():
|
||||||
for k in cache.keys():
|
# VERY BIG TODO: differentiate between None as in 'unlimited timerange' and None as in 'time doesnt matter here'!
|
||||||
# VERY BIG TODO: differentiate between None as in 'unlimited timerange' and None as in 'time doesnt matter here'!
|
if scrobbletime is None or (k[3] is None or scrobbletime >= k[3]) and (k[4] is None or scrobbletime <= k[4]):
|
||||||
if scrobbletime is None or (k[3] is None or scrobbletime >= k[3]) and (k[4] is None or scrobbletime <= k[4]):
|
cleared += 1
|
||||||
cleared += 1
|
del cache[k]
|
||||||
del cache[k]
|
else:
|
||||||
else:
|
kept += 1
|
||||||
kept += 1
|
log(f"Invalidated {cleared} of {cleared+kept} DB cache entries")
|
||||||
log(f"Invalidated {cleared} of {cleared+kept} DB cache entries")
|
|
||||||
|
|
||||||
|
|
||||||
def invalidate_entity_cache():
|
def invalidate_entity_cache():
|
||||||
@ -121,8 +121,8 @@ def trim_cache():
|
|||||||
#cache.set_size(targetsize)
|
#cache.set_size(targetsize)
|
||||||
#cache.set_size(HIGH_NUMBER)
|
#cache.set_size(HIGH_NUMBER)
|
||||||
cache.clear()
|
cache.clear()
|
||||||
if cache.get_size() > CACHE_ADJUST_STEP:
|
#if cache.get_size() > CACHE_ADJUST_STEP:
|
||||||
cache.set_size(cache.get_size() - CACHE_ADJUST_STEP)
|
# cache.set_size(cache.get_size() - CACHE_ADJUST_STEP)
|
||||||
|
|
||||||
#log(f"New RAM usage: {psutil.virtual_memory().percent}%")
|
#log(f"New RAM usage: {psutil.virtual_memory().percent}%")
|
||||||
print_stats()
|
print_stats()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user