<commit_before><?php

final class PhabricatorDataCacheSpec extends PhabricatorCacheSpec {

  private $cacheSummary;

  public function setCacheSummary(array $cache_summary) {
    $this->cacheSummary = $cache_summary;
    return $this;
  }

  public function getCacheSummary() {
    return $this->cacheSummary;
  }

  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;
  }

  private function initAPCSpec() {
    $this
      ->setName(pht('APC User Cache'))
      ->setVersion(phpversion('apc'));

    if (ini_get('apc.enabled')) {
      $this->setIsEnabled(true);
      $this->initAPCCommonSpec();
    } else {
      $this->setIsEnabled(false);
      $this->raiseEnableAPCIssue();
    }
  }

  private function initAPCuSpec() {
    $this
      ->setName(pht('APCu'))
      ->setVersion(phpversion('apcu'));

    if (ini_get('apc.enabled')) {
      $this->setIsEnabled(true);
      $this->getAPCCommonSpec();
    } else {
      $this->setIsEnabled(false);
      $this->raiseEnableAPCIssue();
    }
  }

  private function getNoneSpec() {
    if (version_compare(phpversion(), '5.5', '>=')) {
      $message = pht(
        'Installing the "APCu" PHP extension will improve performance.');

      $this
        ->newIssue('extension.apcu')
        ->setShortName(pht('APCu'))
        ->setName(pht('PHP Extension "APCu" Not Installed'))
        ->setMessage($message)
        ->addPHPExtension('apcu');
    } else {
      $this->raiseInstallAPCIssue();
    }
  }

  private function getAPCCommonSpec() {
    $mem = apc_sma_info();
    $this->setTotalMemory($mem['num_seg'] * $mem['seg_size']);

    $info = apc_cache_info('user');
    $this->setUsedMemory($info['mem_size']);
    $this->setEntryCount(count($info['cache_list']));

    $cache = $info['cache_list'];
    $state = array();
    foreach ($cache as $item) {
      $key = self::getKeyPattern($item['info']);
      if (empty($state[$key])) {
        $state[$key] = array(
          'max' => 0,
          'total' => 0,
          'count' => 0,
        );
      }
      $state[$key]['max'] = max($state[$key]['max'], $item['mem_size']);
      $state[$key]['total'] += $item['mem_size'];
      $state[$key]['count']++;
    }

    $this->setCacheSummary($state);
  }<commit_msg>Fix a bad method call in cache startup.<commit_after><?php

final class PhabricatorDataCacheSpec extends PhabricatorCacheSpec {

  private $cacheSummary;

  public function setCacheSummary(array $cache_summary) {
    $this->cacheSummary = $cache_summary;
    return $this;
  }

  public function getCacheSummary() {
    return $this->cacheSummary;
  }

  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;
  }

  private function initAPCSpec() {
    $this
      ->setName(pht('APC User Cache'))
      ->setVersion(phpversion('apc'));

    if (ini_get('apc.enabled')) {
      $this->setIsEnabled(true);
      $this->initAPCCommonSpec();
    } else {
      $this->setIsEnabled(false);
      $this->raiseEnableAPCIssue();
    }
  }

  private function initAPCuSpec() {
    $this
      ->setName(pht('APCu'))
      ->setVersion(phpversion('apcu'));

    if (ini_get('apc.enabled')) {
      $this->setIsEnabled(true);
      $this->initAPCCommonSpec();
    } else {
      $this->setIsEnabled(false);
      $this->raiseEnableAPCIssue();
    }
  }

  private function getNoneSpec() {
    if (version_compare(phpversion(), '5.5', '>=')) {
      $message = pht(
        'Installing the "APCu" PHP extension will improve performance.');

      $this
        ->newIssue('extension.apcu')
        ->setShortName(pht('APCu'))
        ->setName(pht('PHP Extension "APCu" Not Installed'))
        ->setMessage($message)
        ->addPHPExtension('apcu');
    } else {
      $this->raiseInstallAPCIssue();
    }
  }

  private function initAPCCommonSpec() {
    $mem = apc_sma_info();
    $this->setTotalMemory($mem['num_seg'] * $mem['seg_size']);

    $info = apc_cache_info('user');
    $this->setUsedMemory($info['mem_size']);
    $this->setEntryCount(count($info['cache_list']));

    $cache = $info['cache_list'];
    $state = array();
    foreach ($cache as $item) {
      $key = self::getKeyPattern($item['info']);
      if (empty($state[$key])) {
        $state[$key] = array(
          'max' => 0,
          'total' => 0,
          'count' => 0,
        );
      }
      $state[$key]['max'] = max($state[$key]['max'], $item['mem_size']);
      $state[$key]['total'] += $item['mem_size'];
      $state[$key]['count']++;
    }

    $this->setCacheSummary($state);
  }
{'fraction_non_alphanumeric': 0.17828106852497097, 'fraction_numerical': 0.0019357336430507162, 'mean_word_length': 2.9838087895142635, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5625564', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1684, 'n_words': 297}