mirror of
https://github.com/composer/composer
synced 2025-05-10 09:02:59 +00:00
Add a readonly mode to the cache, fixes #9150
This commit is contained in:
parent
875a4784ed
commit
90332f1dbd
13 changed files with 51 additions and 10 deletions
|
@ -130,6 +130,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
$this->baseUrl = rtrim(preg_replace('{(?:/[^/\\\\]+\.json)?(?:[?#].*)?$}', '', $this->url), '/');
|
||||
$this->io = $io;
|
||||
$this->cache = new Cache($io, $config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $this->url), 'a-z0-9.$~');
|
||||
$this->cache->setReadOnly($config->get('cache-read-only'));
|
||||
$this->versionParser = new VersionParser();
|
||||
$this->loader = new ArrayLoader($this->versionParser);
|
||||
$this->httpDownloader = $httpDownloader;
|
||||
|
@ -1071,7 +1072,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
$data = $response->decodeJson();
|
||||
HttpDownloader::outputWarnings($this->io, $this->url, $data);
|
||||
|
||||
if ($cacheKey) {
|
||||
if ($cacheKey && !$this->cache->isReadOnly()) {
|
||||
if ($storeLastModifiedTime) {
|
||||
$lastModifiedDate = $response->getHeader('last-modified');
|
||||
if ($lastModifiedDate) {
|
||||
|
@ -1155,7 +1156,9 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
$data['last-modified'] = $lastModifiedDate;
|
||||
$json = json_encode($data);
|
||||
}
|
||||
$this->cache->write($cacheKey, $json);
|
||||
if (!$this->cache->isReadOnly()) {
|
||||
$this->cache->write($cacheKey, $json);
|
||||
}
|
||||
|
||||
return $data;
|
||||
} catch (\Exception $e) {
|
||||
|
@ -1238,7 +1241,9 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
$data['last-modified'] = $lastModifiedDate;
|
||||
$json = JsonFile::encode($data, JsonFile::JSON_UNESCAPED_SLASHES | JsonFile::JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
$cache->write($cacheKey, $json);
|
||||
if (!$cache->isReadOnly()) {
|
||||
$cache->write($cacheKey, $json);
|
||||
}
|
||||
$repo->freshMetadataUrls[$filename] = true;
|
||||
|
||||
return $data;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue