|
2 | 2 |
|
3 | 3 | final class PhabricatorDataCacheSpec extends PhabricatorCacheSpec {
|
4 | 4 |
|
| 5 | + private $cacheSummary; |
| 6 | + |
| 7 | + public function setCacheSummary(array $cache_summary) { |
| 8 | + $this->cacheSummary = $cache_summary; |
| 9 | + return $this; |
| 10 | + } |
| 11 | + |
| 12 | + public function getCacheSummary() { |
| 13 | + return $this->cacheSummary; |
| 14 | + } |
| 15 | + |
5 | 16 | public static function getActiveCacheSpec() {
|
6 | 17 | $spec = new PhabricatorDataCacheSpec();
|
7 | 18 | // NOTE: If APCu is installed, it reports that APC is installed.
|
@@ -79,6 +90,43 @@ private static function getAPCCommonSpec(PhabricatorDataCacheSpec $spec) {
|
79 | 90 | $info = apc_cache_info('user');
|
80 | 91 | $spec->setUsedMemory($info['mem_size']);
|
81 | 92 | $spec->setEntryCount(count($info['cache_list']));
|
| 93 | + |
| 94 | + $cache = $info['cache_list']; |
| 95 | + $state = array(); |
| 96 | + foreach ($cache as $item) { |
| 97 | + $key = self::getKeyPattern($item['info']); |
| 98 | + if (empty($state[$key])) { |
| 99 | + $state[$key] = array( |
| 100 | + 'max' => 0, |
| 101 | + 'total' => 0, |
| 102 | + 'count' => 0, |
| 103 | + ); |
| 104 | + } |
| 105 | + $state[$key]['max'] = max($state[$key]['max'], $item['mem_size']); |
| 106 | + $state[$key]['total'] += $item['mem_size']; |
| 107 | + $state[$key]['count']++; |
| 108 | + } |
| 109 | + |
| 110 | + $spec->setCacheSummary($state); |
| 111 | + } |
| 112 | + |
| 113 | + private static function getKeyPattern($key) { |
| 114 | + // If this key isn't in the current cache namespace, don't reveal any |
| 115 | + // information about it. |
| 116 | + $namespace = PhabricatorEnv::getEnvConfig('phabricator.cache-namespace'); |
| 117 | + if (strncmp($key, $namespace.':', strlen($namespace) + 1)) { |
| 118 | + return '<other-namespace>'; |
| 119 | + } |
| 120 | + |
| 121 | + $key = preg_replace('/(?<![a-zA-Z])\d+(?![a-zA-Z])/', 'N', $key); |
| 122 | + $key = preg_replace('/PHID-[A-Z]{4}-[a-z0-9]{20}/', 'PHID', $key); |
| 123 | + |
| 124 | + // TODO: We should probably standardize how digests get embedded into cache |
| 125 | + // keys to make this rule more generic. |
| 126 | + $key = preg_replace('/:celerity:.*$/', ':celerity:X', $key); |
| 127 | + $key = preg_replace('/:pkcs8:.*$/', ':pkcs8:X', $key); |
| 128 | + |
| 129 | + return $key; |
82 | 130 | }
|
83 | 131 |
|
84 | 132 | }
|
0 commit comments