1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of CacheTool. |
5
|
|
|
* |
6
|
|
|
* (c) Samuel Gordalina <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace CacheTool\Command; |
13
|
|
|
|
14
|
|
|
use CacheTool\Util\Formatter; |
15
|
|
|
use Symfony\Component\Console\Helper\Table; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
|
19
|
|
|
class ApcuCacheInfoKeysCommand extends ApcuCacheInfoCommand |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
24 |
|
protected function configure() |
25
|
|
|
{ |
26
|
|
|
$this |
27
|
24 |
|
->setName('apcu:cache:info:keys') |
28
|
24 |
|
->setDescription('Shows APCu keys cache information') |
29
|
24 |
|
->setHelp(''); |
30
|
24 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
36
|
|
|
{ |
37
|
1 |
|
$this->ensureExtensionLoaded('apcu'); |
38
|
|
|
|
39
|
1 |
|
$info = $this->getCacheTool()->apcu_cache_info(false); |
40
|
1 |
|
$this->normalize($info); |
41
|
|
|
|
42
|
1 |
|
if (empty($info)) { |
43
|
|
|
throw new \RuntimeException("Could not fetch info from APCu"); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$header = [ |
47
|
1 |
|
'Hits', |
48
|
|
|
'Accessed', |
49
|
|
|
'Deleted', |
50
|
|
|
'Memory size', |
51
|
|
|
'Key', |
52
|
|
|
]; |
53
|
|
|
|
54
|
1 |
|
$table = new Table($output); |
55
|
|
|
$table |
56
|
1 |
|
->setHeaders($header) |
57
|
1 |
|
->setRows($this->processFilelist($info['cache_list'])) |
58
|
|
|
; |
59
|
|
|
|
60
|
1 |
|
$table->render(); |
61
|
|
|
|
62
|
1 |
|
return 0; |
63
|
|
|
} |
64
|
|
|
|
65
|
1 |
|
protected function processFileList(array $cacheList) |
66
|
|
|
{ |
67
|
1 |
|
$list = []; |
68
|
|
|
|
69
|
1 |
|
foreach ($cacheList as $item) { |
70
|
|
|
$list[] = [ |
71
|
|
|
number_format($item['num_hits']), |
72
|
|
|
$item['access_time'] > 0 ? 'Yes' : 'No', |
73
|
|
|
$item['deletion_time'] > 0 ? 'Yes' : 'No', |
74
|
|
|
Formatter::bytes($item['mem_size']), |
75
|
|
|
$item['info'], |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
return $list; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|