From f93c66b4308d16fe553773a6cc1ce8e76bd617bb Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Wed, 20 Jan 2016 10:43:55 +0100 Subject: [PATCH] Add HIT/MISS result in cache profile call table --- lib/Alchemy/Phrasea/Core/Profiler/TraceableCache.php | 12 ++++++++---- templates/web/debug/cache.html.twig | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/Alchemy/Phrasea/Core/Profiler/TraceableCache.php b/lib/Alchemy/Phrasea/Core/Profiler/TraceableCache.php index 8b9e438592..3944f5c2c0 100644 --- a/lib/Alchemy/Phrasea/Core/Profiler/TraceableCache.php +++ b/lib/Alchemy/Phrasea/Core/Profiler/TraceableCache.php @@ -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; } /** diff --git a/templates/web/debug/cache.html.twig b/templates/web/debug/cache.html.twig index 0e31cda516..8723a41d23 100644 --- a/templates/web/debug/cache.html.twig +++ b/templates/web/debug/cache.html.twig @@ -88,6 +88,7 @@ # Call type Key + Hit / Miss @@ -100,6 +101,7 @@ {% if call['type'] != 'fetch' %}{% endif %} {{ call['key'] }} + {% if call['hit'] %}HIT{% else %}MISS{% endif %} {% endfor %}