Provide 'bin/cache', for managing caches

Summary:
See <https://github.com/facebook/phabricator/issues/323>. We have a very old cache management script which doesn't purge all the modern caches (and does purge some caches which are no longer in use). Update it so it purges all the modern caches (remarkup, general, changeset), no longer purges outdated caches, and is easier to use.

Also delete a lot of "this script has moved" scripts from the last few rounds of similar cleanup, I believe all of these have been in master for at least several months, which should be enough time for users to get used to the new stuff.

Test Plan: Ran `bin/cache` with various arguments. Verified caches were purged.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D5978
This commit is contained in:
epriestley
2013-05-20 10:16:35 -07:00
parent 3990b38b5b
commit e01ceaa07f
14 changed files with 138 additions and 180 deletions

View File

@@ -0,0 +1,99 @@
<?php
final class PhabricatorCacheManagementPurgeWorkflow
extends PhabricatorSearchManagementWorkflow {
protected function didConstruct() {
$this
->setName('purge')
->setSynopsis('Drop data from caches.')
->setArguments(
array(
array(
'name' => 'purge-all',
'help' => 'Purge all caches.',
),
array(
'name' => 'purge-remarkup',
'help' => 'Purge the remarkup cache.',
),
array(
'name' => 'purge-changeset',
'help' => 'Purge the Differential changeset cache.',
),
array(
'name' => 'purge-general',
'help' => 'Purge the general cache.',
),
));
}
public function execute(PhutilArgumentParser $args) {
$console = PhutilConsole::getConsole();
$purge_all = $args->getArg('purge-all');
$purge = array(
'remarkup' => $purge_all || $args->getArg('purge-remarkup'),
'changeset' => $purge_all || $args->getArg('purge-changeset'),
'general' => $purge_all || $args->getArg('purge-general'),
);
if (!array_filter($purge)) {
$list = array();
foreach ($purge as $key => $ignored) {
$list[] = "'--purge-".$key."'";
}
throw new PhutilArgumentUsageException(
"Specify which cache or caches to purge, or use '--purge-all'. ".
"Available caches are: ".implode(', ', $list).". Use '--help' ".
"for more information.");
}
if ($purge['remarkup']) {
$console->writeOut("Purging remarkup cache...");
$this->purgeRemarkupCache();
$console->writeOut("done.\n");
}
if ($purge['changeset']) {
$console->writeOut("Purging changeset cache...");
$this->purgeChangesetCache();
$console->writeOut("done.\n");
}
if ($purge['general']) {
$console->writeOut("Purging general cache...");
$this->purgeGeneralCache();
$console->writeOut("done.\n");
}
}
private function purgeRemarkupCache() {
$conn_w = id(new PhabricatorMarkupCache())->establishConnection('w');
queryfx(
$conn_w,
'TRUNCATE TABLE %T',
id(new PhabricatorMarkupCache())->getTableName());
}
private function purgeChangesetCache() {
$conn_w = id(new DifferentialChangeset())->establishConnection('w');
queryfx(
$conn_w,
'TRUNCATE TABLE %T',
DifferentialChangeset::TABLE_CACHE);
}
private function purgeGeneralCache() {
$conn_w = id(new PhabricatorMarkupCache())->establishConnection('w');
queryfx(
$conn_w,
'TRUNCATE TABLE %T',
'cache_general');
}
}

View File

@@ -0,0 +1,10 @@
<?php
abstract class PhabricatorCacheManagementWorkflow
extends PhutilArgumentWorkflow {
final public function isExecutable() {
return true;
}
}