def store_build_cache(
        self,
        cmds: List[str],
        build_dir: str,
        cache_key: str,
        filter_func: Callable[[str], bool] = is_cache_artifact,
    ) -> bool:
        """See docstring of implemented method interface in parent class"""
        cache_dir = self.cache_dir
        key_cache_dir = os.path.join(cache_dir, cache_key)

        # We create a temporary directory first, so we can do an
        # atomic update later to prevent race conditions
        # in a distributed / parallel build setting
        random_str = secrets.token_hex(16)

        # the temp_cache_dir will be renamed to key_cache_dir
        # atomically later. It needs to be on same file system
        # for atomic rename, so we put it into the same folder.
        temp_cache_dir = key_cache_dir + f".{random_str}.tmp"
        try:
            os.makedirs(temp_cache_dir, exist_ok=False)
        except OSError:
            _LOGGER.warn(
                f"CACHE: Failed to create tempdir {temp_cache_dir}. Cannot write cache entries."
            )
            return False
        basepath = Path(build_dir)
        target_basepath = Path(temp_cache_dir)
        copy_files = [
            p.relative_to(basepath) for p in basepath.rglob("*") if not p.is_dir()
        ]
        for filepath in copy_files:
            src_path = basepath / filepath
            if not filter_func(str(filepath)):
                continue

            target_path = target_basepath / filepath
            target_parent = target_path.parent
            if target_parent != target_basepath:
                os.makedirs(str(target_parent), exist_ok=True)
            shutil.copy2(
                str(src_path),
                str(target_path),
                follow_symlinks=True,
            )  # Use copy2, so the file metadata (incl. last modified time) is preserved
            _LOGGER.info(f"CACHE: storing {filepath} into {key_cache_dir}: ")
        try:
            os.rename(
                temp_cache_dir, key_cache_dir
            )  # Atomic update to prevent race condition
            return True
        except OSError:
            _LOGGER.info(
                f"CACHE: update race conflict - {key_cache_dir} already exists. (Note: No error! This can be expected to happen occasionally.))"
            )
            shutil.rmtree(temp_cache_dir, ignore_errors=True)
            return False
See docstring of implemented method interface in parent class
python/aitemplate/backend/build_cache_base.py