Path: blob/master/src/applications/config/controller/services/PhabricatorConfigCacheController.php
12262 views
<?php12final class PhabricatorConfigCacheController3extends PhabricatorConfigServicesController {45public function handleRequest(AphrontRequest $request) {6$viewer = $this->getViewer();789$purge_button = id(new PHUIButtonView())10->setText(pht('Purge Caches'))11->setHref('/config/cache/purge/')12->setTag('a')13->setWorkflow(true)14->setIcon('fa-exclamation-triangle');1516$title = pht('Cache Status');17$header = $this->buildHeaderView($title, $purge_button);1819$code_box = $this->renderCodeBox();20$data_box = $this->renderDataBox();2122$page = array(23$code_box,24$data_box,25);2627$crumbs = $this->newCrumbs()28->addTextCrumb($title);2930$content = id(new PHUITwoColumnView())31->setHeader($header)32->setFooter($page);3334$nav = $this->newNavigation('cache');3536return $this->newPage()37->setTitle($title)38->setCrumbs($crumbs)39->setNavigation($nav)40->appendChild($content);41}4243private function renderCodeBox() {44$cache = PhabricatorOpcodeCacheSpec::getActiveCacheSpec();45$properties = id(new PHUIPropertyListView());46$this->renderCommonProperties($properties, $cache);47return $this->buildConfigBoxView(pht('Opcode Cache'), $properties);48}4950private function renderDataBox() {51$cache = PhabricatorDataCacheSpec::getActiveCacheSpec();5253$properties = id(new PHUIPropertyListView());5455$this->renderCommonProperties($properties, $cache);5657$table = null;58if ($cache->getName() !== null) {59$total_memory = $cache->getTotalMemory();6061$summary = $cache->getCacheSummary();62$summary = isort($summary, 'total');63$summary = array_reverse($summary, true);6465$rows = array();66foreach ($summary as $key => $info) {67$rows[] = array(68$key,69pht('%s', new PhutilNumber($info['count'])),70phutil_format_bytes($info['max']),71phutil_format_bytes($info['total']),72sprintf('%.1f%%', (100 * ($info['total'] / $total_memory))),73);74}7576$table = id(new AphrontTableView($rows))77->setHeaders(78array(79pht('Pattern'),80pht('Count'),81pht('Largest'),82pht('Total'),83pht('Usage'),84))85->setColumnClasses(86array(87'wide',88'n',89'n',90'n',91'n',92));9394$table = $this->buildConfigBoxView(pht('Cache Storage'), $table);95}9697$properties = $this->buildConfigBoxView(pht('Data Cache'), $properties);9899return array($properties, $table);100}101102private function renderCommonProperties(103PHUIPropertyListView $properties,104PhabricatorCacheSpec $cache) {105106if ($cache->getName() !== null) {107$name = $this->renderYes($cache->getName());108} else {109$name = $this->renderNo(pht('None'));110}111$properties->addProperty(pht('Cache'), $name);112113if ($cache->getIsEnabled()) {114$enabled = $this->renderYes(pht('Enabled'));115} else {116$enabled = $this->renderNo(pht('Not Enabled'));117}118$properties->addProperty(pht('Enabled'), $enabled);119120$version = $cache->getVersion();121if ($version) {122$properties->addProperty(pht('Version'), $this->renderInfo($version));123}124125if ($cache->getName() === null) {126return;127}128129$mem_total = $cache->getTotalMemory();130$mem_used = $cache->getUsedMemory();131132if ($mem_total) {133$percent = 100 * ($mem_used / $mem_total);134135$properties->addProperty(136pht('Memory Usage'),137pht(138'%s of %s',139phutil_tag('strong', array(), sprintf('%.1f%%', $percent)),140phutil_format_bytes($mem_total)));141}142143$entry_count = $cache->getEntryCount();144if ($entry_count !== null) {145$properties->addProperty(146pht('Cache Entries'),147pht('%s', new PhutilNumber($entry_count)));148}149150}151152private function renderYes($info) {153return array(154id(new PHUIIconView())->setIcon('fa-check', 'green'),155' ',156$info,157);158}159160private function renderNo($info) {161return array(162id(new PHUIIconView())->setIcon('fa-times-circle', 'red'),163' ',164$info,165);166}167168private function renderInfo($info) {169return array(170id(new PHUIIconView())->setIcon('fa-info-circle', 'grey'),171' ',172$info,173);174}175176}177178179