X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=fba%2Fcache.py;h=22c2b00ba2ae725d4416d08b5f40f624fb5c4cfc;hb=75fa3f40dff62d1b312cb4bb29470a4df7605440;hp=068fd35f07b4ef1000910c2caf22f639ad366d88;hpb=ad0e8ee96f0dd23c04e491b01a23000b63cab854;p=fba.git diff --git a/fba/cache.py b/fba/cache.py index 068fd35..22c2b00 100644 --- a/fba/cache.py +++ b/fba/cache.py @@ -14,51 +14,50 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . - # Cache for redundant SQL queries -cache = {} +_cache = {} ##### Cache ##### -def is_cache_initialized(key: str) -> bool: - return key in cache +def key_exists(key: str) -> bool: + return key in _cache -def set_all_cache_key(key: str, rows: list, value: any): - # NOISY-DEBUG: print(f"DEBUG: key='{key}',rows()={len(rows)},value[]={type(value)} - CALLED!") +def set_all(key: str, rows: list, value: any): + # DEBUG: print(f"DEBUG: key='{key}',rows()={len(rows)},value[]={type(value)} - CALLED!") if type(key) != str: raise ValueError("Parameter key[]='{type(key)}' is not 'str'") - elif not is_cache_initialized(key): - # NOISY-DEBUG: print(f"DEBUG: Cache for key='{key}' not initialized.") - cache[key] = {} + elif not key_exists(key): + # DEBUG: print(f"DEBUG: Cache for key='{key}' not initialized.") + _cache[key] = {} for sub in rows: - # NOISY-DEBUG: print(f"DEBUG: Setting key='{key}',sub[{type(sub)}]='{sub}'") + # DEBUG: print(f"DEBUG: Setting key='{key}',sub[{type(sub)}]='{sub}'") if isinstance(sub, tuple): - cache[key][sub[0]] = value + _cache[key][sub[0]] = value else: print(f"WARNING: Unsupported type row[]='{type(row)}'") - # NOISY-DEBUG: print("DEBUG: EXIT!") + # DEBUG: print("DEBUG: EXIT!") -def set_cache_key(key: str, sub: str, value: any): +def set_sub_key(key: str, sub: str, value: any): if type(key) != str: raise ValueError("Parameter key[]='{type(key)}' is not 'str'") elif type(sub) != str: raise ValueError("Parameter sub[]='{type(sub)}' is not 'str'") - elif not is_cache_initialized(key): + elif not key_exists(key): print(f"WARNING: Bad method call, key='{key}' is not initialized yet.") - raise Exception(f"Cache for key='{key}' is not initialized, but function called") + raise Exception(f"Cache for key='{key}' is not initialized, but function invoked") - cache[key][sub] = value + _cache[key][sub] = value -def is_cache_key_set(key: str, sub: str) -> bool: +def sub_key_exists(key: str, sub: str) -> bool: if type(key) != str: raise ValueError("Parameter key[]='{type(key)}' is not 'str'") elif type(sub) != str: raise ValueError("Parameter sub[]='{type(sub)}' is not 'str'") - elif not is_cache_initialized(key): + elif not key_exists(key): print(f"WARNING: Bad method call, key='{key}' is not initialized yet.") - raise Exception(f"Cache for key='{key}' is not initialized, but function called") + raise Exception(f"Cache for key='{key}' is not initialized, but function invoked") - return sub in cache[key] + return sub in _cache[key]