Skip to content

Commit c3696f0

Browse files
committed
Add expire TTL to secondary runtime key.
1 parent dc33981 commit c3696f0

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/Predis.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ private function cache(string $key, string $value, int $cacheTime = null, float
124124

125125
if ($cacheTime !== null) {
126126
$this->client->expire($key, $cacheTime);
127+
$this->client->expire("{$key}.runtime", $cacheTime);
127128
}
128129
} catch (\Exception $e) {
129130
// We don't want exceptions in accessing the cache to break functionality.

tests/PredisTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ public function memoizeCallableRefreshRequest()
9696
[$this->equalTo($key), $this->equalTo($cachedValue)],
9797
[$this->equalTo("{$key}.runtime"), $this->lessThan(1)]
9898
);
99-
$client->expects($this->once())->method('expire')->with($this->equalTo($key), $this->equalTo($cacheTime));
99+
$client->expects($this->exactly(2))->method('expire')->withConsecutive(
100+
[$this->equalTo($key), $this->equalTo($cacheTime)],
101+
[$this->equalTo("{$key}.runtime"), $this->equalTo($cacheTime)]
102+
);
100103

101104
$memoizer = new Predis($client, false, 100);
102105

@@ -128,7 +131,10 @@ public function memoizeCallableWithUncachedKey()
128131
[$this->equalTo($key), $this->equalTo($cachedValue)],
129132
[$this->equalTo("{$key}.runtime"), $this->lessThan(1)]
130133
);
131-
$client->expects($this->once())->method('expire')->with($this->equalTo($key), $this->equalTo($cacheTime));
134+
$client->expects($this->exactly(2))->method('expire')->withConsecutive(
135+
[$this->equalTo($key), $this->equalTo($cacheTime)],
136+
[$this->equalTo("{$key}.runtime"), $this->equalTo($cacheTime)]
137+
);
132138

133139
$memoizer = new Predis($client);
134140

0 commit comments

Comments
 (0)