def METHOD_NAME(host: str, port: int = 80, preferipv6: bool = False) -> str:
    """Happyeyeballs function, with caching of the results"""
    # Find out if a cached result is available, and recent enough:
    timecurrent = int(time.time())  # current time in seconds since epoch
    retentionseconds = 100
    hostkey = (host, port, preferipv6)  # Example key: ('ssl.astraweb.com', 563, True)
    try:
        # Let's check the time:
        timecached = METHOD_NAME.happylist[hostkey][1]
        if timecurrent - timecached <= retentionseconds:
            return METHOD_NAME.happylist[hostkey][0]
    except:
        # Exception, so entry not there, so we have to fill it out
        pass
    # we only arrive here if the entry has to be determined. So let's do that:
    # We have to determine the (new) best IP address
    start = time.perf_counter()
    ipv4delay = 0
    try:
        # Check if there is an AAAA / IPv6 result for this host:
        socket.getaddrinfo(host, port, socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_IP, socket.AI_CANONNAME)
        # preferipv6, AND at least one IPv6 found, so give IPv4 (!) a delay so IPv6 has a head start and is preferred
        if preferipv6:
            ipv4delay = 0.1
    except:
        pass
    result_queue = queue.Queue()  # queue used for threads giving back the results
    try:
        # Get all IP (IPv4 and IPv6) addresses:
        allinfo = socket.getaddrinfo(host, port, 0, 0, socket.IPPROTO_TCP)
        for info in allinfo:
            address = info[4][0]
            resolver_thread = threading.Thread(target=do_socket_connect, args=(result_queue, address, port, ipv4delay))
            resolver_thread.daemon = True
            resolver_thread.start()
        result = None  # default return value, used if none of threads says True/"OK", so no connect on any IP address
        # start reading from the Queue for message from the threads:
        for _ in range(len(allinfo)):
            connect_result = result_queue.get()  # get a response
            if connect_result[1]:
                result = connect_result[0]
                break  # the first True/"OK" is enough, so break out of for loop
    except:
        result = None
    logging.info("Quickest IP address for %s (port %s, preferipv6 %s) is %s", host, port, preferipv6, result)
    delay = int(1000 * (time.perf_counter() - start))
    logging.debug("Happy Eyeballs lookup and port connect took %s ms", delay)
    # We're done. Store and return the result
    if result:
        METHOD_NAME.happylist[hostkey] = (result, timecurrent)
    return result