Merge pull request #8874 from Seldaek/cache_successes
Cache successful requests to make sure subsequent loadPackages calls do not do the same requests for nothingpull/8880/head
commit
a9ae54d1bb
|
@ -70,6 +70,14 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
||||||
private $hasPartialPackages;
|
private $hasPartialPackages;
|
||||||
private $partialPackagesByName;
|
private $partialPackagesByName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO v3 should make this private once we can drop PHP 5.3 support
|
||||||
|
* @private
|
||||||
|
* @var array list of package names which are fresh and can be loaded from the cache directly in case loadPackage is called several times
|
||||||
|
* useful for v2 metadata repositories with lazy providers
|
||||||
|
*/
|
||||||
|
public $freshMetadataUrls = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO v3 should make this private once we can drop PHP 5.3 support
|
* TODO v3 should make this private once we can drop PHP 5.3 support
|
||||||
* @private
|
* @private
|
||||||
|
@ -1150,6 +1158,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
||||||
return new Promise(function ($resolve, $reject) { $resolve(array('packages' => array())); });
|
return new Promise(function ($resolve, $reject) { $resolve(array('packages' => array())); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($this->freshMetadataUrls[$filename]) && $lastModifiedTime) {
|
||||||
|
// make it look like we got a 304 response
|
||||||
|
return new Promise(function ($resolve, $reject) { $resolve(true); });
|
||||||
|
}
|
||||||
|
|
||||||
$httpDownloader = $this->httpDownloader;
|
$httpDownloader = $this->httpDownloader;
|
||||||
if ($this->eventDispatcher) {
|
if ($this->eventDispatcher) {
|
||||||
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename);
|
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename);
|
||||||
|
@ -1173,6 +1186,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
||||||
|
|
||||||
$json = $response->getBody();
|
$json = $response->getBody();
|
||||||
if ($json === '' && $response->getStatusCode() === 304) {
|
if ($json === '' && $response->getStatusCode() === 304) {
|
||||||
|
$repo->freshMetadataUrls[$filename] = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1186,6 +1200,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
||||||
$json = JsonFile::encode($data, JsonFile::JSON_UNESCAPED_SLASHES | JsonFile::JSON_UNESCAPED_UNICODE);
|
$json = JsonFile::encode($data, JsonFile::JSON_UNESCAPED_SLASHES | JsonFile::JSON_UNESCAPED_UNICODE);
|
||||||
}
|
}
|
||||||
$cache->write($cacheKey, $json);
|
$cache->write($cacheKey, $json);
|
||||||
|
$repo->freshMetadataUrls[$filename] = true;
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue