Skip to content

Commit 5beb0b7

Browse files
committed
fix MongoStore:: increment to ignore expired cache entries
1 parent 0aed655 commit 5beb0b7

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/Cache/MongoStore.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,18 @@ public function get($key): mixed
182182
#[Override]
183183
public function increment($key, $value = 1): int|float|false
184184
{
185+
$now = $this->getUTCDateTime();
186+
185187
$result = $this->collection->findOneAndUpdate(
186188
[
187189
'_id' => $this->prefix . $key,
190+
'expires_at' => ['$gt' => $now],
188191
],
189192
[
190193
'$inc' => ['value' => $value],
191194
],
192195
[
196+
'projection' => ['value' => 1, 'expires_at' => 1],
193197
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
194198
],
195199
);
@@ -198,12 +202,6 @@ public function increment($key, $value = 1): int|float|false
198202
return false;
199203
}
200204

201-
if ($result['expires_at'] <= $this->getUTCDateTime()) {
202-
$this->forgetIfExpired($key);
203-
204-
return false;
205-
}
206-
207205
return $result['value'];
208206
}
209207

0 commit comments

Comments
 (0)