public static function getActiveCacheSpec()
 {
     $spec = new PhabricatorDataCacheSpec();
     // NOTE: If APCu is installed, it reports that APC is installed.
     if (extension_loaded('apc') && !extension_loaded('apcu')) {
         $spec->initAPCSpec();
     } else {
         if (extension_loaded('apcu')) {
             $spec->initAPCuSpec();
         } else {
             $spec->initNoneSpec();
         }
     }
     return $spec;
 }
 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);
 }
 protected function executeChecks()
 {
     $code_cache = PhabricatorOpcodeCacheSpec::getActiveCacheSpec();
     $data_cache = PhabricatorDataCacheSpec::getActiveCacheSpec();
     $issues = $code_cache->getIssues() + $data_cache->getIssues();
     foreach ($issues as $issue) {
         $this->addIssue($issue);
     }
 }
 private function renderDataBox()
 {
     $cache = PhabricatorDataCacheSpec::getActiveCacheSpec();
     $properties = id(new PHUIPropertyListView());
     $this->renderCommonProperties($properties, $cache);
     $table = null;
     if ($cache->getName() !== null) {
         $total_memory = $cache->getTotalMemory();
         $summary = $cache->getCacheSummary();
         $summary = isort($summary, 'total');
         $summary = array_reverse($summary, true);
         $rows = array();
         foreach ($summary as $key => $info) {
             $rows[] = array($key, pht('%s', new PhutilNumber($info['count'])), phutil_format_bytes($info['max']), phutil_format_bytes($info['total']), sprintf('%.1f%%', 100 * ($info['total'] / $total_memory)));
         }
         $table = id(new AphrontTableView($rows))->setHeaders(array(pht('Pattern'), pht('Count'), pht('Largest'), pht('Total'), pht('Usage')))->setColumnClasses(array('wide', 'n', 'n', 'n', 'n'));
     }
     return id(new PHUIObjectBoxView())->setHeaderText(pht('Data Cache'))->addPropertyList($properties)->setTable($table);
 }