From 1e565d9eb27859204f388de89ea5a1e9cc4d279b Mon Sep 17 00:00:00 2001 From: Rod Payne Date: Sat, 23 Mar 2024 19:40:36 -0600 Subject: [PATCH] Use cache in get_ip_address_info. (#494) --- parsedmarc/utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/parsedmarc/utils.py b/parsedmarc/utils.py index 313d3a8..50ca8d0 100644 --- a/parsedmarc/utils.py +++ b/parsedmarc/utils.py @@ -313,10 +313,15 @@ def get_ip_address_info(ip_address, ip_db_path=None, cache=None, offline=False, """ ip_address = ip_address.lower() - if cache: + if cache is not None: info = cache.get(ip_address, None) if info: + logger.debug("IP address " + ip_address + " was found in cache") return info + else: + logger.debug("IP address " + ip_address + " not found in cache") + else: + logger.debug("IP address cache not specified") info = OrderedDict() info["ip_address"] = ip_address if offline: @@ -333,6 +338,9 @@ def get_ip_address_info(ip_address, ip_db_path=None, cache=None, offline=False, base_domain = get_base_domain(reverse_dns) info["base_domain"] = base_domain + if cache is not None: + cache[ip_address] = info + return info