Skip to content

Commit e655423

Browse files
CopilotmglamanCopilot
authored
Add --no-cache global flag to bypass Drupal.org CDN caching (#325)
* Initial plan * Add --no-cache global option to bypass Drupal.org HTTP caching Co-authored-by: mglaman <3698644+mglaman@users.noreply.github.com> * Update src/Api/Client.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mglaman <3698644+mglaman@users.noreply.github.com> Co-authored-by: Matt Glaman <nmd.matt@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e46b5be commit e655423

4 files changed

Lines changed: 40 additions & 9 deletions

File tree

skills/drupalorg-cli/SKILL.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,21 @@ drupalorg maintainer:release-notes <ref1> [ref2] [--format=json|md|html]
154154
```bash
155155
# Install the drupalorg-cli agent skill into .claude/skills/drupalorg-cli/
156156
drupalorg skill:install
157+
```
158+
159+
## Cache Bypass
160+
161+
Drupal.org uses HTTP caching (CDN/Varnish). If you need fresh data — e.g. after a
162+
new comment was posted — pass `--no-cache` to any command:
157163

158-
# Clear the local API cache
159-
drupalorg cache:clear
164+
```bash
165+
drupalorg issue:show <nid> --with-comments --format=llm --no-cache
166+
drupalorg mr:list [nid] --format=llm --no-cache
160167
```
161168

169+
`--no-cache` sends `Cache-Control: no-cache, no-store, must-revalidate` and
170+
`Pragma: no-cache` headers so the upstream CDN returns a fresh response.
171+
162172
## Error Handling
163173

164174
| Error | Cause | Recovery |

src/Api/Client.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Client
2222
*/
2323
public const API_URL = 'https://www.drupal.org/api-d7/';
2424

25-
public function __construct()
25+
public function __construct(bool $noCache = false)
2626
{
2727
$stack = HandlerStack::create();
2828
$stack->push(GuzzleRetryMiddleware::factory([
@@ -31,16 +31,22 @@ public function __construct()
3131
'default_retry_multiplier' => 1.5,
3232
]), 'retry');
3333

34+
$headers = [
35+
'User-Agent' => 'DrupalOrgCli/0.0.1',
36+
'Accept' => 'application/json',
37+
'Accept-Encoding' => '*',
38+
];
39+
if ($noCache) {
40+
$headers['Cache-Control'] = 'no-cache, no-store, max-age=0';
41+
$headers['Pragma'] = 'no-cache';
42+
}
43+
3444
$this->client = new \GuzzleHttp\Client(
3545
[
3646
'base_uri' => self::API_URL,
3747
'cookies' => true,
3848
'handler' => $stack,
39-
'headers' => [
40-
'User-Agent' => 'DrupalOrgCli/0.0.1',
41-
'Accept' => 'application/json',
42-
'Accept-Encoding' => '*',
43-
],
49+
'headers' => $headers,
4450
]
4551
);
4652
}

src/Cli/Application.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Composer\InstalledVersions;
66
use Symfony\Component\Console\Application as ParentApplication;
7+
use Symfony\Component\Console\Input\InputDefinition;
8+
use Symfony\Component\Console\Input\InputOption;
79

810
class Application extends ParentApplication
911
{
@@ -23,6 +25,18 @@ public function __construct()
2325
$this->addCommands($this->getCommands());
2426
}
2527

28+
protected function getDefaultInputDefinition(): InputDefinition
29+
{
30+
$definition = parent::getDefaultInputDefinition();
31+
$definition->addOption(new InputOption(
32+
'no-cache',
33+
null,
34+
InputOption::VALUE_NONE,
35+
'Bypass Drupal.org HTTP caching and fetch a fresh response.'
36+
));
37+
return $definition;
38+
}
39+
2640
/**
2741
* @return \Symfony\Component\Console\Command\Command[]
2842
*/

src/Cli/Command/Command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ protected function initialize(
4545
) : $output;
4646
$this->stdIn = $input;
4747
self::$interactive = $input->isInteractive();
48-
$this->client = new Client();
48+
$noCache = $input->hasOption('no-cache') && (bool) $input->getOption('no-cache');
49+
$this->client = new Client($noCache);
4950
}
5051

5152
protected function debug(string $message): void

0 commit comments

Comments
 (0)