Skip to content

Commit

Permalink
Use cache in get_ip_address_info. (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodpayne authored Mar 24, 2024
1 parent 3a1360a commit 1e565d9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion parsedmarc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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


Expand Down

0 comments on commit 1e565d9

Please sign in to comment.