Skip to content

Commit 551b709

Browse files
Add missing cache engine method proxies (#1084)
1 parent 2f38294 commit 551b709

2 files changed

Lines changed: 46 additions & 5 deletions

File tree

‎src/Cache/Engine/DebugEngine.php‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,21 @@ public function set($key, $value, $ttl = null): bool
152152
return $result;
153153
}
154154

155+
/**
156+
* @inheritDoc
157+
*/
158+
public function add(string $key, mixed $value): bool
159+
{
160+
$start = microtime(true);
161+
$result = $this->_engine->add($key, $value);
162+
$duration = microtime(true) - $start;
163+
164+
$this->track('set');
165+
$this->log('add', $duration, $key);
166+
167+
return $result;
168+
}
169+
155170
/**
156171
* @inheritDoc
157172
*/
@@ -186,6 +201,25 @@ public function get(string $key, mixed $default = null): mixed
186201
return $result;
187202
}
188203

204+
/**
205+
* @inheritDoc
206+
*/
207+
public function has(string $key): bool
208+
{
209+
$start = microtime(true);
210+
$result = $this->_engine->has($key);
211+
$duration = microtime(true) - $start;
212+
$metric = 'hit';
213+
if (!$result) {
214+
$metric = 'miss';
215+
}
216+
217+
$this->track("get {$metric}");
218+
$this->log('has', $duration, $key);
219+
220+
return $result;
221+
}
222+
189223
/**
190224
* @inheritDoc
191225
*/

‎tests/TestCase/Cache/Engine/DebugEngineTest.php‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,20 @@ public function testInitErrorOnInvalidConfig()
100100
public function testProxyMethodsTracksMetrics()
101101
{
102102
$this->engine->get('key');
103+
$this->engine->has('key');
103104
$this->engine->set('key', 'value');
104105
$this->engine->get('key');
106+
$this->engine->has('key');
107+
$this->engine->add('new-key', 'value');
105108
$this->engine->delete('key');
106109
$this->engine->increment('key');
107110
$this->engine->decrement('key');
108111

109112
$result = $this->engine->metrics();
110-
$this->assertSame(3, $result['set']);
113+
$this->assertSame(4, $result['set']);
111114
$this->assertSame(1, $result['delete']);
112-
$this->assertSame(1, $result['get miss']);
113-
$this->assertSame(1, $result['get hit']);
115+
$this->assertSame(2, $result['get miss']);
116+
$this->assertSame(2, $result['get hit']);
114117
}
115118

116119
/**
@@ -121,7 +124,9 @@ public function testProxyMethodsTracksMetrics()
121124
public function testProxyMethodLogs()
122125
{
123126
$this->engine->get('key');
127+
$this->engine->has('key');
124128
$this->engine->set('key', 'value');
129+
$this->engine->add('new-key', 'value');
125130
$this->engine->delete('key');
126131
$this->engine->increment('key');
127132
$this->engine->decrement('key');
@@ -131,9 +136,11 @@ public function testProxyMethodLogs()
131136
$this->engine->clearGroup('group');
132137

133138
$logs = $this->logger->read();
134-
$this->assertCount(9, $logs);
139+
$this->assertCount(11, $logs);
135140
$this->assertStringStartsWith('info: :test: get `key`', $logs[0]);
136-
$this->assertStringStartsWith('info: :test: set `key`', $logs[1]);
141+
$this->assertStringStartsWith('info: :test: has `key`', $logs[1]);
142+
$this->assertStringStartsWith('info: :test: set `key`', $logs[2]);
143+
$this->assertStringStartsWith('info: :test: add `new-key`', $logs[3]);
137144
}
138145

139146
/**

0 commit comments

Comments
 (0)