Skip to content

Commit 2c93fa3

Browse files
authored
Merge pull request #5 from srjlewis/master
Fix for expiry ttl, as couchbase >= v4, now can use DateTimeInterface for the ttl
2 parents c445d4e + bd11a22 commit 2c93fa3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ protected function driverWrite(ExtendedCacheItemInterface $item): bool
263263
$this->getCollection()->upsert(
264264
$item->getEncodedKey(),
265265
$this->encodeDocument($this->driverPreWrap($item)),
266-
(new UpsertOptions())->expiry($item->getTtl())
266+
(new UpsertOptions())->expiry($item->getExpirationDate())
267267
);
268268
return true;
269269
} catch (CouchbaseException) {

tests/Couchbasev4.test.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@
7070
$cache1->set('forkSuccessTestKey1', $value1);
7171
$cache2->set('forkSuccessTestKey2', $value2);
7272

73+
// 1576800000 is the int limit within Couchbase for the ttl before the need to use DateTime
74+
// so using an int like '\time() + 3600' would produce an error, to reproduce the error
75+
// within phpFastCache we need to push the date 1576800001s in the future to overflow the ttl int
76+
if($cache->set('bigTTL', 'test', new DateInterval('PT1576800001S'))) {
77+
$testHelper->assertPass('Set with large ttl succeeded');
78+
} else {
79+
$testHelper->assertFail('Set with large ttl failed');
80+
}
81+
7382
try {
7483
\Phpfastcache\Extensions\Drivers\Couchbasev4\Driver::prepareToFork();
7584
$pid = \pcntl_fork();

0 commit comments

Comments
 (0)