Add HIT/MISS result in cache profile call table

This commit is contained in:
Thibaud Fabre
2016-01-20 10:43:55 +01:00
parent b5ed9d51f5
commit f93c66b430
2 changed files with 10 additions and 4 deletions

View File

@@ -32,11 +32,13 @@ class TraceableCache implements Cache, PhraseaCache
$this->cache = $cache;
}
private function collect($type, $id)
private function collect($type, $id, $hit = true, $result = null)
{
$this->calls[] = [
'type' => $type,
'key' => $id
'key' => $id,
'result' => $result,
'hit' => (bool) $hit
];
}
@@ -65,9 +67,11 @@ class TraceableCache implements Cache, PhraseaCache
*/
public function fetch($id)
{
$this->collect('fetch', $id);
$value = $this->cache->fetch($id);
return $this->cache->fetch($id);
$this->collect('fetch', $id, $value != false, $value);
return $value;
}
/**

View File

@@ -88,6 +88,7 @@
<th>#</th>
<th>Call type</th>
<th>Key</th>
<th>Hit / Miss</th>
</tr>
</thead>
<tbody>
@@ -100,6 +101,7 @@
{% if call['type'] != 'fetch' %}</strong>{% endif %}
</td>
<td>{{ call['key'] }}</td>
<td>{% if call['hit'] %}HIT{% else %}<strong>MISS</strong>{% endif %}</td>
</tr>
{% endfor %}
</tbody>