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; $this->cache = $cache;
} }
private function collect($type, $id) private function collect($type, $id, $hit = true, $result = null)
{ {
$this->calls[] = [ $this->calls[] = [
'type' => $type, 'type' => $type,
'key' => $id 'key' => $id,
'result' => $result,
'hit' => (bool) $hit
]; ];
} }
@@ -65,9 +67,11 @@ class TraceableCache implements Cache, PhraseaCache
*/ */
public function fetch($id) 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>#</th>
<th>Call type</th> <th>Call type</th>
<th>Key</th> <th>Key</th>
<th>Hit / Miss</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -100,6 +101,7 @@
{% if call['type'] != 'fetch' %}</strong>{% endif %} {% if call['type'] != 'fetch' %}</strong>{% endif %}
</td> </td>
<td>{{ call['key'] }}</td> <td>{{ call['key'] }}</td>
<td>{% if call['hit'] %}HIT{% else %}<strong>MISS</strong>{% endif %}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>