Change the file download cache key with the processed URL, implement custom cache key

main
Fränz Friederes 4 years ago
parent bd2f321527
commit 57e1ce6cdb
No known key found for this signature in database
GPG Key ID: 583D205C93C01BC0

@ -113,6 +113,10 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$urls[$index] = array(
'base' => $url,
'processed' => $processedUrl,
// we use the complete download url here to avoid conflicting entries
// from different packages, which would potentially allow a given package
// in a third party repo to pre-populate the cache for the same package in
// packagist for example.
'cacheKey' => $this->getCacheKey($package, $processedUrl)
);
}
@ -136,6 +140,11 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
if ($eventDispatcher) {
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $httpDownloader, $url['processed'], 'package', $package);
$eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
if ($preFileDownloadEvent->getCustomCacheKey() !== null) {
$url['cacheKey'] = $this->getCacheKey($package, $preFileDownloadEvent->getCustomCacheKey());
} else if ($preFileDownloadEvent->getProcessedUrl() !== $url['processed']) {
$url['cacheKey'] = $this->getCacheKey($package, $preFileDownloadEvent->getProcessedUrl());
}
$url['processed'] = $preFileDownloadEvent->getProcessedUrl();
}
@ -398,14 +407,9 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
return $url;
}
private function getCacheKey(PackageInterface $package, $processedUrl)
private function getCacheKey(PackageInterface $package, $key)
{
// we use the complete download url here to avoid conflicting entries
// from different packages, which would potentially allow a given package
// in a third party repo to pre-populate the cache for the same package in
// packagist for example.
$cacheKey = sha1($processedUrl);
$cacheKey = sha1($key);
return $package->getName().'/'.$cacheKey.'.'.$package->getDistType();
}

@ -32,6 +32,11 @@ class PreFileDownloadEvent extends Event
*/
private $processedUrl;
/**
* @var string
*/
private $customCacheKey;
/**
* @var string
*/
@ -88,6 +93,26 @@ class PreFileDownloadEvent extends Event
$this->processedUrl = $processedUrl;
}
/**
* Retrieves a custom package cache key for this download.
*
* @return string
*/
public function getCustomCacheKey()
{
return $this->customCacheKey;
}
/**
* Sets a custom package cache key for this download.
*
* @param string $customCacheKey New cache key
*/
public function setCustomCacheKey($customCacheKey)
{
$this->customCacheKey = $customCacheKey;
}
/**
* Returns the type of this download (package, metadata).
*

Loading…
Cancel
Save