Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit b8a08ba

Browse files
committed
Improved CacheCollector data
1 parent 182df6b commit b8a08ba

File tree

3 files changed

+64
-10
lines changed

3 files changed

+64
-10
lines changed

DataCollector/CacheCollector.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use phpFastCache\Bundle\Service\Cache;
66
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
7+
use phpFastCache\CacheManager;
78
use Symfony\Component\HttpFoundation\Request;
89
use Symfony\Component\HttpFoundation\Response;
910
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
@@ -35,6 +36,7 @@ public function collect(Request $request, Response $response, \Exception $except
3536
$size = 0;
3637
$stats = [];
3738
$instances = [];
39+
$driverUsed = [];
3840

3941
/** @var $cache */
4042
foreach ($this->cache->getInstances() as $instanceName => $cache) {
@@ -43,15 +45,21 @@ public function collect(Request $request, Response $response, \Exception $except
4345
}
4446
$stats[$instanceName] = $cache->getStats();
4547
$instances[$instanceName] = [
46-
'driverName' => $cache->getDriverName(),
47-
'driverConfig' => $cache->getConfig()
48+
'driverName' => $cache->getDriverName(),
49+
'driverConfig' => $cache->getConfig()
4850
];
51+
$driverUsed[$cache->getDriverName()] = get_class($cache);
4952
}
5053

5154
$this->data = [
52-
'instances' => $instances,
53-
'stats' => $stats,
54-
'size' => $size
55+
'driverUsed' => $driverUsed,
56+
'instances' => $instances,
57+
'stats' => $stats,
58+
'size' => $size,
59+
'hits' => [
60+
'read' => (int) CacheManager::$ReadHits,
61+
'write' => (int) CacheManager::$WriteHits,
62+
]
5563
];
5664
}
5765

@@ -65,6 +73,16 @@ public function getInstances()
6573
return $this->data['instances'];
6674
}
6775

76+
public function getDriverUsed()
77+
{
78+
return $this->data['driverUsed'];
79+
}
80+
81+
public function getHits()
82+
{
83+
return $this->data['hits'];
84+
}
85+
6886
public function getSize()
6987
{
7088
/**
@@ -78,4 +96,4 @@ public function getName()
7896
{
7997
return 'phpfastcache';
8098
}
81-
}
99+
}

DependencyInjection/Configuration.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace phpFastCache\Bundle\DependencyInjection;
44

5+
use phpFastCache\CacheManager;
56
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
67
use Symfony\Component\Config\Definition\ConfigurationInterface;
78

@@ -27,8 +28,8 @@ public function getConfigTreeBuilder()
2728
->useAttributeAsKey('name')
2829
->prototype('array')
2930
->children()
30-
->enumNode('type')->isRequired()->values(array('Files', 'MongoDb', 'Apc'))->end() // @TODO : Add all available drivers
31-
->arrayNode('parameters')->isRequired()->prototype('scalar')->end()
31+
->enumNode('type')->isRequired()->values(CacheManager::getStaticAllDrivers())->end() // @TODO : Add all available drivers
32+
->arrayNode('parameters')->isRequired()->prototype('variable')->end()
3233
->end()
3334
->end()
3435
->end() // drivers

Resources/views/data_collector/template.html.twig

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@
1111
<b>Cache instances</b>
1212
<span class="sf-toolbar-status">{{ collector.stats|length }}</span>
1313
</div>
14+
<div class="sf-toolbar-info-piece">
15+
<b>Cache Size</b>
16+
<span class="sf-toolbar-status">{{ collector.size|sizeFormat(1) }}</span>
17+
</div>
18+
<div class="sf-toolbar-info-piece">
19+
<b>Read hits</b>
20+
<span class="sf-toolbar-status">{{ collector.hits.read }}</span>
21+
</div>
22+
<div class="sf-toolbar-info-piece">
23+
<b>Write hits</b>
24+
<span class="sf-toolbar-status">{{ collector.hits.write }}</span>
25+
</div>
26+
<div class="sf-toolbar-info-piece">
27+
<b>Cache Driver</b>
28+
{% if collector.driverUsed|length == 0 %}
29+
<span>None</span>
30+
{% elseif collector.driverUsed|length == 1 %}
31+
<span><abbr title="{{ collector.driverUsed|first }}">{{ collector.driverUsed|keys|first }}</abbr></span>
32+
{% else %}
33+
<span>Multiple ({{ collector.driverUsed|length }})</span>
34+
{% endif %}
35+
</div>
36+
1437
{% endset %}
1538

1639
{{ include('@WebProfiler/Profiler/toolbar_item.html.twig') }}
@@ -38,6 +61,18 @@
3861
<span class="value"> {{ collector.stats|length }}</span>
3962
<span class="label">Cache Instances</span>
4063
</div>
64+
<div class="metric">
65+
<span class="value"> {{ collector.driverUsed|length }}</span>
66+
<span class="label">Drivers used</span>
67+
</div>
68+
<div class="metric">
69+
<span class="value"> {{ collector.hits.read }}</span>
70+
<span class="label">Read hits</span>
71+
</div>
72+
<div class="metric">
73+
<span class="value"> {{ collector.hits.write }}</span>
74+
<span class="label">Write hits</span>
75+
</div>
4176
</div>
4277

4378
<h2>PhpFastCache Cache Instance</h2>
@@ -50,11 +85,11 @@
5085
<tbody>
5186
<tr>
5287
<th>Driver Name</th>
53-
<td>{{ collector.instances[name].driverName }}</td>
88+
<td><strong>{{ collector.instances[name].driverName }}</strong> (<small><code>{{ collector.driverUsed[collector.instances[name].driverName] }}</code></small>)</td>
5489
</tr>
5590
<tr>
5691
<th>Driver Info</th>
57-
<td>{{ stat.info }}</td>
92+
<td>{{ stat.info|nl2br }}</td>
5893
</tr>
5994
<tr>
6095
<th>Driver Size</th>

0 commit comments

Comments
 (0)