]> git.mxchange.org Git - fba.git/blobdiff - fba/helpers/software.py
Continued:
[fba.git] / fba / helpers / software.py
index f224ba4e478da7e9b86d7a3aac54dc58599c7e04..3eca4faf83dd479069b449939b15a3e60f6ac3a7 100644 (file)
@@ -29,6 +29,12 @@ relays = [
     "pub-relay"
 ]
 
+# In-function cache
+_cache = {
+    # Cache for function alias()
+    "alias" : {},
+}
+
 def alias(software: str) -> str:
     logger.debug("software='%s'- CALLED!", software)
 
@@ -36,6 +42,11 @@ def alias(software: str) -> str:
         raise ValueError(f"software[]='{type(software)}' is not type 'str'")
     elif software == "":
         raise ValueError("Parameter 'software' is empty")
+    elif software in _cache["alias"]:
+        logger.debug("Returning cached value='%s' for function 'alias' - EXIT!", _cache["alias"][software])
+        return _cache["alias"][software]
+
+    key = software
 
     logger.debug("software='%s'- BEFORE!", software)
     software = tidyup.domain(software)
@@ -126,6 +137,9 @@ def alias(software: str) -> str:
         logger.debug("software='%s' is being cleaned up further ...")
         software = software.rstrip("!").strip()
 
+    # Set cache
+    _cache["alias"][key] = software
+
     logger.debug("software[%s]='%s' - EXIT!", type(software), software)
     return software