Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Redis clear #2355

Draft
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Commands/Env/ClearCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ class ClearCacheCommand extends TerminusCommand implements SiteAwareInterface
* @aliases env:cc
*
* @param string $site_env Site & environment in the format `site-name.env`
* @param array $options
* @option bool $framework_cache [true|false] Clear the CMS cache
* @option bool $varnish_cache [true|false] Clear the edge cache
*
* @usage <site>.<env> Clears caches for <site>'s <env> environment.
*
* @throws \Pantheon\Terminus\Exceptions\TerminusProcessException
* @throws \Pantheon\Terminus\Exceptions\TerminusException
*/
public function clearCache($site_env)
public function clearCache($site_env, $options = ['framework_cache' => true, 'varnish_cache' => false,])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 on adding flags to the existing env:cc command. Note that it's not reliable to turn off the varnish cache here, as the Drupal hook will clear the varnish cache even if the ygg workflow does not.

The existing behavior may be inconsistent with WordPress, i.e. WordPress might not clear the varnish cache if the ygg workflow does not. Ideally we would fix WordPress, and hook its cache clear operation the same way we do for Drupal. Maybe having ygg clear the varnish cache invariantly here would be a reasonable workaround.

{
$this->requireSiteIsNotFrozen($site_env);
$env = $this->getEnv($site_env);

$this->processWorkflow($env->clearCache());
$this->processWorkflow($env->clearCache($options));
$this->log()->notice(
'Caches cleared on {env}.',
['env' => $env->getName()]
Expand Down
44 changes: 44 additions & 0 deletions src/Commands/Redis/ClearCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Pantheon\Terminus\Commands\Redis;

use Pantheon\Terminus\Commands\TerminusCommand;
use Pantheon\Terminus\Commands\WorkflowProcessingTrait;
use Pantheon\Terminus\Exceptions\TerminusProcessException;
use Pantheon\Terminus\Site\SiteAwareInterface;
use Pantheon\Terminus\Site\SiteAwareTrait;

/**
* Class ClearCommand
* @package Pantheon\Terminus\Commands\Redis
*/
class ClearCommand extends TerminusCommand implements SiteAwareInterface
{
use SiteAwareTrait;
use WorkflowProcessingTrait;

/**
* Clear the Redis cache for a site environment.
*
* @authorize
*
* @command redis:clear
*
* @param string $site_id Site name
*
* @usage <site> Clear the Redis cache for <site>.
*
* @throws \Pantheon\Terminus\Exceptions\TerminusProcessException
* @throws \Pantheon\Terminus\Exceptions\TerminusException
*/
public function clear($site_env)
{
$this->requireSiteIsNotFrozen($site_env);
$site = $this->getSite();
$env = $this->getEnv($site_env);

$workflow = $site->getRedis()->clear($env);
$this->processWorkflow($workflow);
$this->log()->notice($workflow->getMessage());
}
}
4 changes: 2 additions & 2 deletions src/Models/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public function changeConnectionMode($mode)
*
* @return Workflow
*/
public function clearCache()
public function clearCache(array $options = [])
{
return $this->getWorkflows()->create('clear_cache', ['params' => ['framework_cache' => true,],]);
return $this->getWorkflows()->create('clear_cache', ['params' => $options,]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Redis extends AddOnModel
* @param Environment $env An object representing the environment on which to clear the Redis cache
* @return Workflow
*/
public function clear($env)
public function clear(Environment $env)
{
// @Todo: Change this when the env model conversion is merged
return $env->getWorkflows()->create('clear_redis_cache');
Expand Down