From: Roland Häder Date: Tue, 28 Nov 2023 15:03:52 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0f8d501ff89cfbbaeddd0df46711edae87a60cfe;p=fba.git Continued: - also cache invocations of raise_on() which is being very often invoked --- diff --git a/fba/helpers/domain.py b/fba/helpers/domain.py index d79fb20..9ab00d0 100644 --- a/fba/helpers/domain.py +++ b/fba/helpers/domain.py @@ -38,6 +38,9 @@ def raise_on(domain: str): raise ValueError(f"Parameter domain[]='{type(domain)}' is not of type 'str'") elif domain == "": raise ValueError("Parameter 'domain' is empty") + elif "raise_on" in _cache and domain in _cache["raise_on"]: + logger.debug("Returning cached is_found='%s' - EXIT!", _cache["raise_on"][domain]) + return _cache["raise_on"][domain] elif domain.lower() != domain: raise ValueError(f"Parameter domain='{domain}' must be all lower-case") elif not validators.domain(domain.split("/")[0]): @@ -50,7 +53,11 @@ def raise_on(domain: str): raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!") elif domain.endswith(".tld"): raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!") + elif not "raise_on" in _cache: + logger.debug("Initializing cache for function 'raise_on' ...") + _cache["raise_on"] = {} + _cache["raise_on"][domain] = True logger.debug("EXIT!") def is_in_url(domain: str, url: str) -> bool: