def should_cache(self) -> bool:
        """Determine whether to cache the dependencies and built wheel."""
        from unearth import vcs_support

        if not self.environment.project.core.state.enable_cache:
            return False

        link, source_dir = self.candidate.link, self._source_dir
        if self.req.editable:
            return False
        if self.req.is_named:
            return True
        if self.req.is_vcs:
            if not source_dir:
                # If the candidate isn't prepared, we can't cache it
                return False
            assert link
            vcs_backend = vcs_support.get_backend(link.vcs, self.environment.project.core.ui.verbosity)
            return vcs_backend.is_immutable_revision(source_dir, link)
        if link and not (link.is_file and link.file_path.is_dir()):
            # Cache if the link contains egg-info like 'foo-1.0'
            return _egg_info_re.search(link.filename) is not None
        return False
Determine whether to cache the dependencies and built wheel.
src/pdm/models/candidates.py