import pathlib
import hashlib


def hash_file(path: pathlib.Path) -> str:
    """Return the SHA-256 hash of a file as hexadecimal string.

    The results of this functions are cached in order to avoid multiple computations for the same file.

    Args:
        path: The path of the file to hash
    """
    sha256 = hashlib.sha256()
    with path.open('rb') as file_handle:
        for chunk in iter(lambda: file_handle.read(1048576), b''):
            sha256.update(chunk)
    return sha256.hexdigest()