def retrieve_build_cache(
        self,
        cmds: List[str],
        build_dir: str,
        from_sources_filter_func: Callable[[str], bool] = is_source,
    ) -> Tuple[bool, Optional[str]]:
        """See docstring of implemented method interface in parent class"""
        if should_skip_build_cache():
            _LOGGER.info(f"CACHE: Skipped build cache for {build_dir}")
            return False, None
        self.maybe_cleanup(self.lru_retention_hours, self.cleanup_max_age_seconds)
        cache_dir = self.cache_dir
        dir_hash = create_dir_hash(
            cmds,
            build_dir,
            filter_func=from_sources_filter_func,
            debug=self.debug,
            content_replacer=lambda path: self.makefile_normalizer(
                path, memoize_replacements=True
            ),
        )
        key_cache_dir = os.path.join(cache_dir, dir_hash)
        if os.path.exists(key_cache_dir):
            _LOGGER.info(f"CACHE: Using cached build results for {build_dir}")
            target_basepath = Path(build_dir)
            src_basepath = Path(key_cache_dir)
            copy_files = [
                p.relative_to(src_basepath)
                for p in src_basepath.rglob("*")
                if not p.is_dir()
            ]
            for filepath in copy_files:
                target_path = target_basepath / filepath
                target_parent = target_path.parent
                src_path = src_basepath / filepath
                if target_parent != target_basepath:
                    os.makedirs(str(target_parent), exist_ok=True)
                shutil.copy(
                    str(src_path),
                    str(target_path),
                    follow_symlinks=True,
                )  # Using shutil.copy intentionally instead of copy2, so the file modification time is updated, and file owner
                # is not copied. When you retrieve the file from cache, it is yours.
                _LOGGER.debug(f"CACHE: retrieved {filepath}")
            # make sure the last modified timestamp is updated, so we can
            # evict cache directories which are too old using a separate script
            os.utime(key_cache_dir)
            return True, dir_hash
        _LOGGER.info(f"CACHE: No results found for {build_dir}")
        return False, dir_hash
See docstring of implemented method interface in parent class
python/aitemplate/backend/build_cache_base.py