From b05a55488390a81ffc6928a5b6f2254a3f51651e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 11 Nov 2012 15:31:50 +0100 Subject: [PATCH] Add cache-files-ttl setting, and docs for the cache --- doc/04-schema.md | 4 ++++ src/Composer/Command/ConfigCommand.php | 2 ++ src/Composer/Config.php | 10 ++++++++++ src/Composer/Factory.php | 5 ++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/doc/04-schema.md b/doc/04-schema.md index a44ca605e..e76a55ae7 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -596,6 +596,10 @@ The following options are supported: * **notify-on-install:** Defaults to `true`. Composer allows repositories to define a notification URL, so that they get notified whenever a package from that repository is installed. This option allows you to disable that behaviour. +* **cache-files-ttl:** Defaults to `15552000` (6 months). Composer caches all + dist (zip, tar, ..) packages that it downloads. Those are purged after six + months of being unused by default. This option allows you to tweak this + duration (in seconds) or disable it completely by setting it to 0. Example: diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index acedf558a..f997dc29e 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -184,6 +184,8 @@ EOT // handle config values $uniqueConfigValues = array( 'process-timeout' => array('is_numeric', 'intval'), + 'cache-ttl' => array('is_numeric', 'intval'), + 'cache-files-ttl' => array('is_numeric', 'intval'), 'vendor-dir' => array('is_string', function ($val) { return $val; }), 'bin-dir' => array('is_string', function ($val) { return $val; }), 'notify-on-install' => array( diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 803b3cbf3..9684edab0 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -120,6 +120,16 @@ class Config return rtrim($this->process(getenv($env) ?: $this->config[$key]), '/\\'); + case 'cache-ttl': + return (int) $this->config[$key]; + + case 'cache-files-ttl': + if (isset($this->config[$key])) { + return (int) $this->config[$key]; + } + + return (int) $this->config['cache-ttl']; + case 'home': return rtrim($this->process($this->config[$key]), '/\\'); diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 7a49131cb..48bae966d 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -240,7 +240,10 @@ class Factory */ public function createDownloadManager(IOInterface $io, Config $config) { - $cache = new Cache($io, $config->get('home').'/cache.files/', 'a-z0-9_./'); + $cache = null; + if ($config->get('cache-files-ttl') > 0) { + $cache = new Cache($io, $config->get('home').'/cache.files/', 'a-z0-9_./'); + } $dm = new Downloader\DownloadManager(); $dm->setDownloader('git', new Downloader\GitDownloader($io, $config));