1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 13:22:42 +01:00

Add dialog to purge opcode/data caches

Summary: Reachable via the cache config page, restricted to admins only. This makes it convenient to hotfix phabricator without requiring a restart.

Test Plan:
  - Local dev machine doesn't have apc, so I get the not installed message.
  - Faked the name and isEnabled parameters, verified dialog shows up as expected.
  - Didn't test clear code

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: tycho.tatitscheff, joshuaspence, Korvin

Differential Revision: https://secure.phabricator.com/D14064
This commit is contained in:
Mihir Kedia 2015-09-10 14:18:52 -07:00 committed by epriestley
parent f8080ce931
commit ae0348aac9
8 changed files with 106 additions and 9 deletions

View file

@ -1842,6 +1842,7 @@ phutil_register_library_map(array(
'PhabricatorConfigOptionType' => 'applications/config/custom/PhabricatorConfigOptionType.php',
'PhabricatorConfigPHIDModule' => 'applications/config/module/PhabricatorConfigPHIDModule.php',
'PhabricatorConfigProxySource' => 'infrastructure/env/PhabricatorConfigProxySource.php',
'PhabricatorConfigPurgeCacheController' => 'applications/config/controller/PhabricatorConfigPurgeCacheController.php',
'PhabricatorConfigRequestExceptionHandlerModule' => 'applications/config/module/PhabricatorConfigRequestExceptionHandlerModule.php',
'PhabricatorConfigResponse' => 'applications/config/response/PhabricatorConfigResponse.php',
'PhabricatorConfigSchemaQuery' => 'applications/config/schema/PhabricatorConfigSchemaQuery.php',
@ -5748,6 +5749,7 @@ phutil_register_library_map(array(
'PhabricatorConfigOptionType' => 'Phobject',
'PhabricatorConfigPHIDModule' => 'PhabricatorConfigModule',
'PhabricatorConfigProxySource' => 'PhabricatorConfigSource',
'PhabricatorConfigPurgeCacheController' => 'PhabricatorConfigController',
'PhabricatorConfigRequestExceptionHandlerModule' => 'PhabricatorConfigModule',
'PhabricatorConfigResponse' => 'AphrontStandaloneHTMLResponse',
'PhabricatorConfigSchemaQuery' => 'Phobject',

View file

@ -6,7 +6,8 @@ final class PhabricatorCacheManagementPurgeWorkflow
protected function didConstruct() {
$this
->setName('purge')
->setSynopsis(pht('Drop data from caches.'))
->setSynopsis(pht('Drop data from caches. APC-based caches can be '.
'purged from the web interface.'))
->setArguments(
array(
array(

View file

@ -5,6 +5,7 @@ abstract class PhabricatorCacheSpec extends Phobject {
private $name;
private $isEnabled = false;
private $version;
private $clearCacheCallback = null;
private $issues = array();
private $usedMemory = 0;
@ -108,4 +109,12 @@ abstract class PhabricatorCacheSpec extends Phobject {
->addPHPConfig('apc.enabled');
}
public function setClearCacheCallback($callback) {
$this->clearCacheCallback = $callback;
return $this;
}
public function getClearCacheCallback() {
return $this->clearCacheCallback;
}
}

View file

@ -34,7 +34,9 @@ final class PhabricatorDataCacheSpec extends PhabricatorCacheSpec {
->setVersion(phpversion('apc'));
if (ini_get('apc.enabled')) {
$this->setIsEnabled(true);
$this
->setIsEnabled(true)
->setClearCacheCallback('apc_clear_cache');
$this->initAPCCommonSpec();
} else {
$this->setIsEnabled(false);
@ -48,7 +50,9 @@ final class PhabricatorDataCacheSpec extends PhabricatorCacheSpec {
->setVersion(phpversion('apcu'));
if (ini_get('apc.enabled')) {
$this->setIsEnabled(true);
$this
->setIsEnabled(true)
->setClearCacheCallback('apc_clear_cache');
$this->initAPCCommonSpec();
} else {
$this->setIsEnabled(false);
@ -118,5 +122,4 @@ final class PhabricatorDataCacheSpec extends PhabricatorCacheSpec {
return $key;
}
}

View file

@ -23,7 +23,9 @@ final class PhabricatorOpcodeCacheSpec extends PhabricatorCacheSpec {
->setVersion(phpversion('apc'));
if (ini_get('apc.enabled')) {
$this->setIsEnabled(true);
$this
->setIsEnabled(true)
->setClearCacheCallback('apc_clear_cache');
$mem = apc_sma_info();
$this->setTotalMemory($mem['num_seg'] * $mem['seg_size']);
@ -109,7 +111,9 @@ final class PhabricatorOpcodeCacheSpec extends PhabricatorCacheSpec {
->setVersion(phpversion('Zend OPcache'));
if (ini_get('opcache.enable')) {
$this->setIsEnabled(true);
$this
->setIsEnabled(true)
->setClearCacheCallback('opcache_reset');
$status = opcache_get_status();
$memory = $status['memory_usage'];
@ -199,5 +203,4 @@ final class PhabricatorOpcodeCacheSpec extends PhabricatorCacheSpec {
$this->raiseInstallAPCIssue();
}
}
}

View file

@ -55,7 +55,10 @@ final class PhabricatorConfigApplication extends PhabricatorApplication {
'' => 'PhabricatorConfigIssueListController',
'(?P<key>[^/]+)/' => 'PhabricatorConfigIssueViewController',
),
'cache/' => 'PhabricatorConfigCacheController',
'cache/' => array(
'' => 'PhabricatorConfigCacheController',
'purge/' => 'PhabricatorConfigPurgeCacheController',
),
'module/' => array(
'(?P<module>[^/]+)/' => 'PhabricatorConfigModuleController',
),

View file

@ -39,8 +39,22 @@ final class PhabricatorConfigCacheController
$this->renderCommonProperties($properties, $cache);
$purge_icon = id(new PHUIIconView())
->setIconFont('fa-exclamation-triangle');
$purge_button = id(new PHUIButtonView())
->setText(pht('Purge Caches'))
->setHref('/config/cache/purge/')
->setTag('a')
->setWorkflow(true)
->setIcon($purge_icon);
$header = id(new PHUIHeaderView())
->setHeader(pht('Opcode Cache'))
->addActionLink($purge_button);
return id(new PHUIObjectBoxView())
->setHeaderText(pht('Opcode Cache'))
->setHeader($header)
->addPropertyList($properties);
}

View file

@ -0,0 +1,62 @@
<?php
final class PhabricatorConfigPurgeCacheController
extends PhabricatorConfigController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$cancel_uri = $this->getApplicationURI('cache/');
$opcode_cache = PhabricatorOpcodeCacheSpec::getActiveCacheSpec();
$data_cache = PhabricatorDataCacheSpec::getActiveCacheSpec();
$opcode_clearable = $opcode_cache->getClearCacheCallback();
$data_clearable = $data_cache->getClearCacheCallback();
if (!$opcode_clearable && !$data_clearable) {
return $this->newDialog()
->setTitle(pht('No Caches to Reset'))
->appendParagraph(
pht('None of the caches on this page can be cleared.'))
->addCancelButton($cancel_uri);
}
if ($request->isDialogFormPost()) {
if ($opcode_clearable) {
call_user_func($opcode_cache->getClearCacheCallback());
}
if ($data_clearable) {
call_user_func($data_cache->getClearCacheCallback());
}
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
}
$caches = id(new PHUIPropertyListView())
->setUser($viewer);
if ($opcode_clearable) {
$caches->addProperty(
pht('Opcode'),
$opcode_cache->getName());
}
if ($data_clearable) {
$caches->addProperty(
pht('Data'),
$data_cache->getName());
}
return $this->newDialog()
->setTitle(pht('Really Clear Cache?'))
->setShortTitle(pht('Really Clear Cache'))
->appendParagraph(pht('This will only affect the current web '.
'frontend. Daemons and any other web frontends may continue '.
'to use older, cached code from their opcache.'))
->appendParagraph(pht('The following caches will be cleared:'))
->appendChild($caches)
->addSubmitButton(pht('Clear Cache'))
->addCancelButton($cancel_uri);
}
}