public function getPackageFilename(PackageGenerator $generator, $identifier, $sha, $repositoryDir, DeploynautLogFile $log) {
		if(!$this->baseDir) throw new \LogicException("Can't use PackageCache without setting BaseDir");

		$buildPath = $this->baseDir . '/' . $this->sanitiseDirName($identifier);
		$filename = "$buildPath/$sha.tar.gz";

		if(!file_exists($this->baseDir)) {
			if(!mkdir($this->baseDir)) throw new \LogicException("Can't create base dir {$this->baseDir}");
		}
		if(!file_exists($buildPath)) {
			if(!mkdir($buildPath)) throw new \LogicException("Can't create build path $buildPath");
		}

		if(file_exists($filename)) {
			$log->write("Using previously generated package $filename");
			// This will ensure that our cache garbage collection will remove least-recently-accessed,
			// rather than oldest.
			touch($filename);
			return $filename;

		} else {
			if($this->cacheSize) $this->reduceDirSizeTo($buildPath, $this->cacheSize-1, $log);

			if($generator->generatePackage($sha, $repositoryDir, $filename, $log)) {
				return $filename;
			}
		}
	}