# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-
# 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]