From 54df62e550736713aefccc7030de3bb06438067e Mon Sep 17 00:00:00 2001 From: Michele Primavera Date: Thu, 13 Aug 2026 15:19:57 +0200 Subject: [PATCH] Add missing cache engine method proxies --- src/Cache/Engine/DebugEngine.php | 34 +++++++++++++++++++ .../TestCase/Cache/Engine/DebugEngineTest.php | 17 +++++++--- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/Cache/Engine/DebugEngine.php b/src/Cache/Engine/DebugEngine.php index 3c4e2e22e..3431aa8cc 100644 --- a/src/Cache/Engine/DebugEngine.php +++ b/src/Cache/Engine/DebugEngine.php @@ -152,6 +152,21 @@ public function set($key, $value, $ttl = null): bool return $result; } + /** + * @inheritDoc + */ + public function add(string $key, mixed $value): bool + { + $start = microtime(true); + $result = $this->_engine->add($key, $value); + $duration = microtime(true) - $start; + + $this->track('set'); + $this->log('add', $duration, $key); + + return $result; + } + /** * @inheritDoc */ @@ -186,6 +201,25 @@ public function get(string $key, mixed $default = null): mixed return $result; } + /** + * @inheritDoc + */ + public function has(string $key): bool + { + $start = microtime(true); + $result = $this->_engine->has($key); + $duration = microtime(true) - $start; + $metric = 'hit'; + if (!$result) { + $metric = 'miss'; + } + + $this->track("get {$metric}"); + $this->log('has', $duration, $key); + + return $result; + } + /** * @inheritDoc */ diff --git a/tests/TestCase/Cache/Engine/DebugEngineTest.php b/tests/TestCase/Cache/Engine/DebugEngineTest.php index a7550d1e1..4f6da19c6 100644 --- a/tests/TestCase/Cache/Engine/DebugEngineTest.php +++ b/tests/TestCase/Cache/Engine/DebugEngineTest.php @@ -100,17 +100,20 @@ public function testInitErrorOnInvalidConfig() public function testProxyMethodsTracksMetrics() { $this->engine->get('key'); + $this->engine->has('key'); $this->engine->set('key', 'value'); $this->engine->get('key'); + $this->engine->has('key'); + $this->engine->add('new-key', 'value'); $this->engine->delete('key'); $this->engine->increment('key'); $this->engine->decrement('key'); $result = $this->engine->metrics(); - $this->assertSame(3, $result['set']); + $this->assertSame(4, $result['set']); $this->assertSame(1, $result['delete']); - $this->assertSame(1, $result['get miss']); - $this->assertSame(1, $result['get hit']); + $this->assertSame(2, $result['get miss']); + $this->assertSame(2, $result['get hit']); } /** @@ -121,7 +124,9 @@ public function testProxyMethodsTracksMetrics() public function testProxyMethodLogs() { $this->engine->get('key'); + $this->engine->has('key'); $this->engine->set('key', 'value'); + $this->engine->add('new-key', 'value'); $this->engine->delete('key'); $this->engine->increment('key'); $this->engine->decrement('key'); @@ -131,9 +136,11 @@ public function testProxyMethodLogs() $this->engine->clearGroup('group'); $logs = $this->logger->read(); - $this->assertCount(9, $logs); + $this->assertCount(11, $logs); $this->assertStringStartsWith('info: :test: get `key`', $logs[0]); - $this->assertStringStartsWith('info: :test: set `key`', $logs[1]); + $this->assertStringStartsWith('info: :test: has `key`', $logs[1]); + $this->assertStringStartsWith('info: :test: set `key`', $logs[2]); + $this->assertStringStartsWith('info: :test: add `new-key`', $logs[3]); } /**