From 6cc0d26e51ace5ba95970a265ee736e9f43d5f69 Mon Sep 17 00:00:00 2001 From: erikatharp Date: Mon, 28 Nov 2022 10:10:02 -0800 Subject: [PATCH 1/7] chore: make refreshTtl optional and default to true; re-order argument list push operations and dictionary increment operation; updates tests accordingly --- src/Cache/SimpleCacheClient.php | 18 ++--- src/Cache/_ScsDataClient.php | 12 +-- tests/Cache/CacheClientTest.php | 135 ++++++++++++++++---------------- 3 files changed, 82 insertions(+), 83 deletions(-) diff --git a/src/Cache/SimpleCacheClient.php b/src/Cache/SimpleCacheClient.php index d9df0cea..f7ddfceb 100644 --- a/src/Cache/SimpleCacheClient.php +++ b/src/Cache/SimpleCacheClient.php @@ -105,17 +105,17 @@ public function listFetch(string $cacheName, string $listName): CacheListFetchRe } public function listPushFront( - string $cacheName, string $listName, string $value, bool $refreshTtl, ?int $ttlSeconds = null, ?int $truncateBackToSize = null + string $cacheName, string $listName, string $value, ?int $truncateBackToSize = null, ?bool $refreshTtl = true, ?int $ttlSeconds = null ): CacheListPushFrontResponse { - return $this->dataClient->listPushFront($cacheName, $listName, $value, $refreshTtl, $truncateBackToSize, $ttlSeconds); + return $this->dataClient->listPushFront($cacheName, $listName, $value, $truncateBackToSize, $refreshTtl, $ttlSeconds); } public function listPushBack( - string $cacheName, string $listName, string $value, bool $refreshTtl, ?int $ttlSeconds = null, ?int $truncateFrontToSize = null + string $cacheName, string $listName, string $value, ?int $truncateFrontToSize = null, ?bool $refreshTtl = true, ?int $ttlSeconds = null ): CacheListPushBackResponse { - return $this->dataClient->listPushBack($cacheName, $listName, $value, $refreshTtl, $truncateFrontToSize, $ttlSeconds); + return $this->dataClient->listPushBack($cacheName, $listName, $value, $truncateFrontToSize, $refreshTtl, $ttlSeconds); } public function listPopFront(string $cacheName, string $listName): CacheListPopFrontResponse @@ -143,7 +143,7 @@ public function listErase(string $cacheName, string $listName, ?int $beginIndex return $this->dataClient->listErase($cacheName, $listName, $beginIndex, $count); } - public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, bool $refreshTtl, ?int $ttlSeconds = null): CacheDictionarySetFieldResponse + public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, ?bool $refreshTtl = true, ?int $ttlSeconds = null): CacheDictionarySetFieldResponse { return $this->dataClient->dictionarySetField($cacheName, $dictionaryName, $field, $value, $refreshTtl, $ttlSeconds); } @@ -163,7 +163,7 @@ public function dictionaryFetch(string $cacheName, string $dictionaryName): Cach return $this->dataClient->dictionaryFetch($cacheName, $dictionaryName); } - public function dictionarySetFields(string $cacheName, string $dictionaryName, array $items, bool $refreshTtl, ?int $ttlSeconds = null): CacheDictionarySetFieldsResponse + public function dictionarySetFields(string $cacheName, string $dictionaryName, array $items, ?bool $refreshTtl = true, ?int $ttlSeconds = null): CacheDictionarySetFieldsResponse { return $this->dataClient->dictionarySetFields($cacheName, $dictionaryName, $items, $refreshTtl, $ttlSeconds); } @@ -174,10 +174,10 @@ public function dictionaryGetFields(string $cacheName, string $dictionaryName, a } public function dictionaryIncrement( - string $cacheName, string $dictionaryName, string $field, bool $refreshTtl, int $amount = 1, ?int $ttlSeconds = null + string $cacheName, string $dictionaryName, string $field, int $amount = 1, ?bool $refreshTtl = true, ?int $ttlSeconds = null ): CacheDictionaryIncrementResponse { - return $this->dataClient->dictionaryIncrement($cacheName, $dictionaryName, $field, $refreshTtl, $amount, $ttlSeconds); + return $this->dataClient->dictionaryIncrement($cacheName, $dictionaryName, $field, $amount, $refreshTtl, $ttlSeconds); } public function dictionaryRemoveField(string $cacheName, string $dictionaryName, string $field): CacheDictionaryRemoveFieldResponse @@ -190,7 +190,7 @@ public function dictionaryRemoveFields(string $cacheName, string $dictionaryName return $this->dataClient->dictionaryRemoveFields($cacheName, $dictionaryName, $fields); } - public function setAddElement(string $cacheName, string $setName, string $element, bool $refreshTtl, ?int $ttlSeconds = null): CacheSetAddElementResponse + public function setAddElement(string $cacheName, string $setName, string $element, ?bool $refreshTtl = true, ?int $ttlSeconds = null): CacheSetAddElementResponse { return $this->dataClient->setAddElement($cacheName, $setName, $element, $refreshTtl, $ttlSeconds); } diff --git a/src/Cache/_ScsDataClient.php b/src/Cache/_ScsDataClient.php index cd3244c0..6b4eb2db 100644 --- a/src/Cache/_ScsDataClient.php +++ b/src/Cache/_ScsDataClient.php @@ -271,7 +271,7 @@ public function listFetch(string $cacheName, string $listName): CacheListFetchRe } public function listPushFront( - string $cacheName, string $listName, string $value, bool $refreshTtl, ?int $truncateBackToSize = null, ?int $ttlSeconds = null + string $cacheName, string $listName, string $value, ?int $truncateBackToSize = null, ?bool $refreshTtl = true, ?int $ttlSeconds = null ): CacheListPushFrontResponse { try { @@ -300,7 +300,7 @@ public function listPushFront( } public function listPushBack( - string $cacheName, string $listName, string $value, bool $refreshTtl, ?int $truncateFrontToSize = null, ?int $ttlSeconds = null + string $cacheName, string $listName, string $value, ?int $truncateFrontToSize = null, ?bool $refreshTtl = true, ?int $ttlSeconds = null ): CacheListPushBackResponse { try { @@ -442,7 +442,7 @@ public function listErase(string $cacheName, string $listName, ?int $beginIndex return new CacheListEraseResponseSuccess(); } - public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, bool $refreshTtl, ?int $ttlSeconds = null): CacheDictionarySetFieldResponse + public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, ?bool $refreshTtl = true, ?int $ttlSeconds = null): CacheDictionarySetFieldResponse { try { validateCacheName($cacheName); @@ -541,7 +541,7 @@ public function dictionaryFetch(string $cacheName, string $dictionaryName): Cach return new CacheDictionaryFetchResponseMiss(); } - public function dictionarySetFields(string $cacheName, string $dictionaryName, array $items, bool $refreshTtl, ?int $ttlSeconds = null): CacheDictionarySetFieldsResponse + public function dictionarySetFields(string $cacheName, string $dictionaryName, array $items, ?bool $refreshTtl = true, ?int $ttlSeconds = null): CacheDictionarySetFieldsResponse { try { validateCacheName($cacheName); @@ -595,7 +595,7 @@ public function dictionaryGetFields(string $cacheName, string $dictionaryName, a } public function dictionaryIncrement( - string $cacheName, string $dictionaryName, string $field, bool $refreshTtl, int $amount = 1, ?int $ttlSeconds = null + string $cacheName, string $dictionaryName, string $field, int $amount = 1, ?bool $refreshTtl = true, ?int $ttlSeconds = null ): CacheDictionaryIncrementResponse { try { @@ -669,7 +669,7 @@ public function dictionaryRemoveFields(string $cacheName, string $dictionaryName return new CacheDictionaryRemoveFieldsResponseSuccess(); } - public function setAddElement(string $cacheName, string $setName, string $element, bool $refreshTt, ?int $ttlSeconds = null): CacheSetAddElementResponse + public function setAddElement(string $cacheName, string $setName, string $element, ?bool $refreshTt = true, ?int $ttlSeconds = null): CacheSetAddElementResponse { try { validateCacheName($cacheName); diff --git a/tests/Cache/CacheClientTest.php b/tests/Cache/CacheClientTest.php index eeef881a..05293e6f 100644 --- a/tests/Cache/CacheClientTest.php +++ b/tests/Cache/CacheClientTest.php @@ -16,7 +16,6 @@ use Momento\Config\Transport\StaticTransportStrategy; use Momento\Logging\NullLoggerFactory; use PHPUnit\Framework\TestCase; -use Psr\Log\NullLogger; use RuntimeException; use TypeError; @@ -495,7 +494,7 @@ public function testListPushFrontFetchHappyPath() $listName = uniqid(); $value = uniqid(); $value2 = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, true, 6000); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttlSeconds: 6000); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(1, $response->asSuccess()->listLength()); @@ -508,7 +507,7 @@ public function testListPushFrontFetchHappyPath() $this->assertCount(1, $values); $this->assertContains($value, $values); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value2, true, 6000); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value2, ttlSeconds: 6000); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(2, $response->asSuccess()->listLength()); @@ -525,11 +524,11 @@ public function testListPushFront_NoRefreshTtl() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, false, 5); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false, ttlSeconds: 5); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, false, 10); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false, ttlSeconds: 10); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -543,11 +542,11 @@ public function testListPushFront_RefreshTtl() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, false, 2); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false, ttlSeconds: 2); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, true, 10); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttlSeconds: 10); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -564,15 +563,15 @@ public function testListPushFront_TruncateList() $value1 = uniqid(); $value2 = uniqid(); $value3 = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value1, false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value1, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value2, false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value2, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value3, false, truncateBackToSize: 2); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value3, 2, false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -586,7 +585,7 @@ public function testListPushFront_TruncateList_NegativeValue() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, false, truncateBackToSize: -1); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, -1, false); $this->assertNotNull($response->asError(), "Expected error but got: $response"); $this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode()); } @@ -596,7 +595,7 @@ public function testListPushBackFetchHappyPath() $listName = uniqid(); $value = uniqid(); $value2 = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, true, 6000); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttlSeconds: 6000); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(1, $response->asSuccess()->listLength()); @@ -609,7 +608,7 @@ public function testListPushBackFetchHappyPath() $this->assertCount(1, $values); $this->assertContains($value, $values); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value2, true, 6000); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value2, ttlSeconds: 6000); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(2, $response->asSuccess()->listLength()); @@ -626,11 +625,11 @@ public function testListPushBack_NoRefreshTtl() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false, 5); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false, ttlSeconds: 5); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false, 10); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false, ttlSeconds: 10); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -644,11 +643,11 @@ public function testListPushBack_RefreshTtl() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false, 2); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false, ttlSeconds: 2); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, true, 10); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttlSeconds: 10); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -665,15 +664,15 @@ public function testListPushBack_TruncateList() $value1 = uniqid(); $value2 = uniqid(); $value3 = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value1, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value1, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value2, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value2, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value3, false, truncateFrontToSize: 2); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value3, 2, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -687,7 +686,7 @@ public function testListPushBack_TruncateList_NegativeValue() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false, truncateFrontToSize: -1); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, -1, refreshTtl: false); $this->assertNotNull($response->asError(), "Expected error but got: $response"); $this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode()); } @@ -706,7 +705,7 @@ public function testListPopFront_HappyPath() $values = []; foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $val, false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); array_unshift($values, $val); @@ -736,7 +735,7 @@ public function testListPopFront_EmptyList() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -761,7 +760,7 @@ public function testListPopBack_HappyPath() $values = []; foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $values[] = $val; @@ -784,7 +783,7 @@ public function testListPopBack_EmptyList() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -810,16 +809,16 @@ public function testListRemoveValue_HappyPath() $valueToRemove = uniqid(); foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $values[] = $val; } - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $valueToRemove, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $valueToRemove, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $valueToRemove, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $valueToRemove, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -846,7 +845,7 @@ public function testListRemoveValues_ValueNotPresent() $values = []; foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $values[] = $val; @@ -872,7 +871,7 @@ public function testListLength_HappyPath() $listName = uniqid(); foreach (range(0, 3) as $i) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -898,7 +897,7 @@ public function testListEraseAll_HappyPath() $listName = uniqid(); foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); } @@ -924,7 +923,7 @@ public function testListEraseRange_HappyPath() $values = []; foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $values[] = $val; @@ -951,7 +950,7 @@ public function testListEraseRange_LargeCountValue() $values = []; foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $values[] = $val; @@ -1075,7 +1074,7 @@ public function testDictionaryRefreshTtl() $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, true, 10); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, ttlSeconds: 10); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1127,7 +1126,7 @@ public function testDictionaryIncrement_NullFieldError() { $dictionaryName = uniqid(); $field = ""; - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, false); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, refreshTtl: false); $this->assertNotNull($response->asError(), "Expected error but got: $response"); $this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode()); } @@ -1136,17 +1135,17 @@ public function testDictionaryIncrement_HappyPath() { $dictionaryName = uniqid(); $field = uniqid(); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, false); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(1, $response->asSuccess()->valueInt()); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, false, 41); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 41, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(42, $response->asSuccess()->valueInt()); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, false, -1042); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: -1042, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(-1000, $response->asSuccess()->valueInt()); @@ -1161,11 +1160,11 @@ public function testDictionaryIncrement_RefreshTtl() { $dictionaryName = uniqid(); $field = uniqid(); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, false, ttlSeconds: 2); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, refreshTtl: false, ttlSeconds: 2); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, true, ttlSeconds: 10); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 10); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(2); @@ -1180,11 +1179,11 @@ public function testDictionaryIncrement_NoRefreshTtl() { $dictionaryName = uniqid(); $field = uniqid(); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, false, ttlSeconds: 5); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, refreshTtl: false, ttlSeconds: 5); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, false, ttlSeconds: 10); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, refreshTtl: false, ttlSeconds: 10); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(6); @@ -1202,12 +1201,12 @@ public function testDictionaryIncrement_SetAndReset() $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, false, 0); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 0, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(10, $response->asSuccess()->valueInt()); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, false, 90); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 90, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(100, $response->asSuccess()->valueInt()); @@ -1216,7 +1215,7 @@ public function testDictionaryIncrement_SetAndReset() $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, false, 0); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 0, refreshTtl: false); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(0, $response->asSuccess()->valueInt()); @@ -1230,7 +1229,7 @@ public function testDictionaryIncrement_FailedPrecondition() $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, true, 1); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 1); $this->assertNotNull($response->asError(), "Expected an error but got: $response"); $this->assertEquals(MomentoErrorCode::FAILED_PRECONDITION_ERROR, $response->asError()->errorCode()); } @@ -1361,10 +1360,10 @@ public function testDictionaryFetch_HappyPath() $value1 = uniqid(); $value2 = uniqid(); $contentDictionary = [$field1 => $value1, $field2 => $value2]; - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field1, $value1, true, 10); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field1, $value1, ttlSeconds: 10); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field2, $value2, true, 10); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field2, $value2, ttlSeconds: 10); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1490,7 +1489,7 @@ public function testDictionarySetFieldsRefreshTtl_HappyPath() $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $content, true, 10); + $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $content, ttlSeconds: 10); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(2); @@ -1689,7 +1688,7 @@ public function testCacheListPopFrontToString_HappyPath() { $listName = uniqid(); $value = "a short value"; - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $response = $this->client->listPopFront($this->TEST_CACHE_NAME, $listName); @@ -1701,7 +1700,7 @@ public function testCacheListPopFrontToString_LongValue() { $listName = uniqid(); $value = str_repeat("a", 256); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $response = $this->client->listPopFront($this->TEST_CACHE_NAME, $listName); @@ -1714,7 +1713,7 @@ public function testCacheListPopBackToString_HappyPath() { $listName = uniqid(); $value = "a short value"; - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $response = $this->client->listPopBack($this->TEST_CACHE_NAME, $listName); @@ -1726,7 +1725,7 @@ public function testCacheListPopBackToString_LongValue() { $listName = uniqid(); $value = str_repeat("a", 256); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $response = $this->client->listPopBack($this->TEST_CACHE_NAME, $listName); @@ -1739,11 +1738,11 @@ public function testCacheListFetchToString_HappyPath() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $response = $this->client->listFetch($this->TEST_CACHE_NAME, $listName); @@ -1756,13 +1755,13 @@ public function testCacheListPushFrontToString_HappyPath() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 1 items"); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 2 items"); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 3 items"); } @@ -1771,13 +1770,13 @@ public function testCacheListPushBackToString_HappyPath() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 1 items"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 2 items"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 3 items"); } @@ -1786,11 +1785,11 @@ public function testCacheListLengthToString_HappyPath() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); $this->assertNull($response->asError()); $response = $this->client->listLength($this->TEST_CACHE_NAME, $listName); @@ -1849,11 +1848,11 @@ public function testDictionaryIncrementToString_HappyPath() $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, "1", false); $this->assertNull($response->asError()); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, false); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, refreshTtl: false); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 2"); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, false, 10); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 10, refreshTtl: false); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 12"); } @@ -1974,7 +1973,7 @@ public function testSetAddElementSetFetch_RefreshTtl() $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, true, 10); + $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, ttlSeconds: 10); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(2); From 2512025a3742125a5a1dc34547f40b07f958dc90 Mon Sep 17 00:00:00 2001 From: erikatharp Date: Mon, 28 Nov 2022 10:16:34 -0800 Subject: [PATCH 2/7] fix: tests --- tests/Cache/CacheClientTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/Cache/CacheClientTest.php b/tests/Cache/CacheClientTest.php index 05293e6f..07182e65 100644 --- a/tests/Cache/CacheClientTest.php +++ b/tests/Cache/CacheClientTest.php @@ -1164,7 +1164,7 @@ public function testDictionaryIncrement_RefreshTtl() $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 10); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, ttlSeconds: 10); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(2); @@ -1613,10 +1613,7 @@ public function testDictionaryGetFieldsDictionaryMissing_HappyPath() $field3 = uniqid(); $response = $this->client->dictionaryGetFields($this->TEST_CACHE_NAME, $dictionaryName, [$field1, $field2, $field3]); $this->assertNull($response->asError()); - $this->assertNotNull($response->asHit(), "Expected a hit but got: $response"); - foreach ($response->asHit()->responses() as $response) { - $this->assertEquals(CacheDictionaryGetFieldResponseMiss::class, $response); - } + $this->assertNotNull($response->asMiss(), "Expected a hit but got: $response"); } public function testDictionaryGetBatchFieldsValuesArray_MixedPath() From 1d5d4ae1087891263ae46b461fbdfe310e2f651e Mon Sep 17 00:00:00 2001 From: erikatharp Date: Mon, 28 Nov 2022 15:39:06 -0800 Subject: [PATCH 3/7] chore: add CollectionTtl class; update tests accordingly --- src/Cache/SimpleCacheClient.php | 26 ++-- src/Cache/_ScsDataClient.php | 45 ++++--- src/Requests/CollectionTtl.php | 46 +++++++ tests/Cache/CacheClientTest.php | 216 ++++++++++++++++---------------- 4 files changed, 199 insertions(+), 134 deletions(-) create mode 100644 src/Requests/CollectionTtl.php diff --git a/src/Cache/SimpleCacheClient.php b/src/Cache/SimpleCacheClient.php index f7ddfceb..a4d8a9cf 100644 --- a/src/Cache/SimpleCacheClient.php +++ b/src/Cache/SimpleCacheClient.php @@ -32,6 +32,8 @@ use Momento\Cache\CacheOperationTypes\ListCachesResponse; use Momento\Config\IConfiguration; use Momento\Logging\ILoggerFactory; +use Momento\Requests\CollectionTtl; +use Momento\Requests\CollectionTtlFactory; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; @@ -105,17 +107,17 @@ public function listFetch(string $cacheName, string $listName): CacheListFetchRe } public function listPushFront( - string $cacheName, string $listName, string $value, ?int $truncateBackToSize = null, ?bool $refreshTtl = true, ?int $ttlSeconds = null + string $cacheName, string $listName, string $value, ?int $truncateBackToSize = null, CollectionTtl $ttl = null ): CacheListPushFrontResponse { - return $this->dataClient->listPushFront($cacheName, $listName, $value, $truncateBackToSize, $refreshTtl, $ttlSeconds); + return $this->dataClient->listPushFront($cacheName, $listName, $value, $truncateBackToSize, $ttl); } public function listPushBack( - string $cacheName, string $listName, string $value, ?int $truncateFrontToSize = null, ?bool $refreshTtl = true, ?int $ttlSeconds = null + string $cacheName, string $listName, string $value, ?int $truncateFrontToSize = null, CollectionTtl $ttl = null ): CacheListPushBackResponse { - return $this->dataClient->listPushBack($cacheName, $listName, $value, $truncateFrontToSize, $refreshTtl, $ttlSeconds); + return $this->dataClient->listPushBack($cacheName, $listName, $value, $truncateFrontToSize, $ttl); } public function listPopFront(string $cacheName, string $listName): CacheListPopFrontResponse @@ -143,9 +145,9 @@ public function listErase(string $cacheName, string $listName, ?int $beginIndex return $this->dataClient->listErase($cacheName, $listName, $beginIndex, $count); } - public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, ?bool $refreshTtl = true, ?int $ttlSeconds = null): CacheDictionarySetFieldResponse + public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, CollectionTtl $ttl = null): CacheDictionarySetFieldResponse { - return $this->dataClient->dictionarySetField($cacheName, $dictionaryName, $field, $value, $refreshTtl, $ttlSeconds); + return $this->dataClient->dictionarySetField($cacheName, $dictionaryName, $field, $value, $ttl); } public function dictionaryGetField(string $cacheName, string $dictionaryName, string $field): CacheDictionaryGetFieldResponse @@ -163,9 +165,9 @@ public function dictionaryFetch(string $cacheName, string $dictionaryName): Cach return $this->dataClient->dictionaryFetch($cacheName, $dictionaryName); } - public function dictionarySetFields(string $cacheName, string $dictionaryName, array $items, ?bool $refreshTtl = true, ?int $ttlSeconds = null): CacheDictionarySetFieldsResponse + public function dictionarySetFields(string $cacheName, string $dictionaryName, array $items, CollectionTtl $ttl = null): CacheDictionarySetFieldsResponse { - return $this->dataClient->dictionarySetFields($cacheName, $dictionaryName, $items, $refreshTtl, $ttlSeconds); + return $this->dataClient->dictionarySetFields($cacheName, $dictionaryName, $items, $ttl); } public function dictionaryGetFields(string $cacheName, string $dictionaryName, array $fields): CacheDictionaryGetFieldsResponse @@ -174,10 +176,10 @@ public function dictionaryGetFields(string $cacheName, string $dictionaryName, a } public function dictionaryIncrement( - string $cacheName, string $dictionaryName, string $field, int $amount = 1, ?bool $refreshTtl = true, ?int $ttlSeconds = null + string $cacheName, string $dictionaryName, string $field, int $amount = 1, CollectionTtl $ttl = null ): CacheDictionaryIncrementResponse { - return $this->dataClient->dictionaryIncrement($cacheName, $dictionaryName, $field, $amount, $refreshTtl, $ttlSeconds); + return $this->dataClient->dictionaryIncrement($cacheName, $dictionaryName, $field, $amount, $ttl); } public function dictionaryRemoveField(string $cacheName, string $dictionaryName, string $field): CacheDictionaryRemoveFieldResponse @@ -190,9 +192,9 @@ public function dictionaryRemoveFields(string $cacheName, string $dictionaryName return $this->dataClient->dictionaryRemoveFields($cacheName, $dictionaryName, $fields); } - public function setAddElement(string $cacheName, string $setName, string $element, ?bool $refreshTtl = true, ?int $ttlSeconds = null): CacheSetAddElementResponse + public function setAddElement(string $cacheName, string $setName, string $element, CollectionTtl $ttl = null): CacheSetAddElementResponse { - return $this->dataClient->setAddElement($cacheName, $setName, $element, $refreshTtl, $ttlSeconds); + return $this->dataClient->setAddElement($cacheName, $setName, $element, $ttl); } public function setFetch(string $cacheName, string $setName): CacheSetFetchResponse diff --git a/src/Cache/_ScsDataClient.php b/src/Cache/_ScsDataClient.php index 6b4eb2db..79c657c0 100644 --- a/src/Cache/_ScsDataClient.php +++ b/src/Cache/_ScsDataClient.php @@ -116,6 +116,8 @@ use Momento\Cache\Errors\SdkError; use Momento\Cache\Errors\UnknownError; use Momento\Config\IConfiguration; +use Momento\Requests\CollectionTtl; +use Momento\Requests\CollectionTtlFactory; use Momento\Utilities\_ErrorConverter; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; @@ -175,6 +177,14 @@ private function ttlToMillis(?int $ttl = null): int return $ttl * 1000; } + private function returnCollectionTtl($ttl): CollectionTtl + { + if (!$ttl) { + return CollectionTtl::fromCacheTtl(); + } + return $ttl; + } + private function processCall(UnaryCall $call): mixed { [$response, $status] = $call->wait(); @@ -271,18 +281,19 @@ public function listFetch(string $cacheName, string $listName): CacheListFetchRe } public function listPushFront( - string $cacheName, string $listName, string $value, ?int $truncateBackToSize = null, ?bool $refreshTtl = true, ?int $ttlSeconds = null + string $cacheName, string $listName, string $value, ?int $truncateBackToSize = null, CollectionTtl $ttl = null ): CacheListPushFrontResponse { try { + $collectionTtl = $this->returnCollectionTtl($ttl); validateCacheName($cacheName); validateListName($listName); validateTruncateSize($truncateBackToSize); - $ttlMillis = $this->ttlToMillis($ttlSeconds); + $ttlMillis = $this->ttlToMillis($collectionTtl->getTtl()); $listPushFrontRequest = new _ListPushFrontRequest(); $listPushFrontRequest->setListName($listName); $listPushFrontRequest->setValue($value); - $listPushFrontRequest->setRefreshTtl($refreshTtl); + $listPushFrontRequest->setRefreshTtl($collectionTtl->getRefreshTtl()); $listPushFrontRequest->setTtlMilliseconds($ttlMillis); if (!is_null($truncateBackToSize)) { $listPushFrontRequest->setTruncateBackToSize($truncateBackToSize); @@ -300,18 +311,19 @@ public function listPushFront( } public function listPushBack( - string $cacheName, string $listName, string $value, ?int $truncateFrontToSize = null, ?bool $refreshTtl = true, ?int $ttlSeconds = null + string $cacheName, string $listName, string $value, ?int $truncateFrontToSize = null, CollectionTtl $ttl = null ): CacheListPushBackResponse { try { + $collectionTtl = $this->returnCollectionTtl($ttl); validateCacheName($cacheName); validateListName($listName); validateTruncateSize($truncateFrontToSize); - $ttlMillis = $this->ttlToMillis($ttlSeconds); + $ttlMillis = $this->ttlToMillis($collectionTtl->getTtl()); $listPushBackRequest = new _ListPushBackRequest(); $listPushBackRequest->setListName($listName); $listPushBackRequest->setValue($value); - $listPushBackRequest->setRefreshTtl($refreshTtl); + $listPushBackRequest->setRefreshTtl($collectionTtl->getRefreshTtl()); $listPushBackRequest->setTtlMilliseconds($ttlMillis); if (!is_null($truncateFrontToSize)) { $listPushBackRequest->setTruncateFrontToSize($truncateFrontToSize); @@ -442,19 +454,20 @@ public function listErase(string $cacheName, string $listName, ?int $beginIndex return new CacheListEraseResponseSuccess(); } - public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, ?bool $refreshTtl = true, ?int $ttlSeconds = null): CacheDictionarySetFieldResponse + public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, CollectionTtl $ttl = null): CacheDictionarySetFieldResponse { try { + $collectionTtl = $this->returnCollectionTtl($ttl); validateCacheName($cacheName); validateDictionaryName($dictionaryName); validateFieldName($field); validateValueName($value); - $ttlMillis = $this->ttlToMillis($ttlSeconds); + $ttlMillis = $this->ttlToMillis($collectionTtl->getTtl()); validateTtl($ttlMillis); $dictionarySetFieldRequest = new _DictionarySetRequest(); $dictionarySetFieldRequest->setDictionaryName($dictionaryName); $dictionarySetFieldRequest->setItems([$this->toSingletonFieldValuePair($field, $value)]); - $dictionarySetFieldRequest->setRefreshTtl($refreshTtl); + $dictionarySetFieldRequest->setRefreshTtl($collectionTtl->getRefreshTtl()); $dictionarySetFieldRequest->setTtlMilliseconds($ttlMillis); $call = $this->grpcManager->client->DictionarySet($dictionarySetFieldRequest, ["cache" => [$cacheName]], ["timeout" => $this->timeout]); $this->processCall($call); @@ -541,14 +554,15 @@ public function dictionaryFetch(string $cacheName, string $dictionaryName): Cach return new CacheDictionaryFetchResponseMiss(); } - public function dictionarySetFields(string $cacheName, string $dictionaryName, array $items, ?bool $refreshTtl = true, ?int $ttlSeconds = null): CacheDictionarySetFieldsResponse + public function dictionarySetFields(string $cacheName, string $dictionaryName, array $items, CollectionTtl $ttl = null): CacheDictionarySetFieldsResponse { try { + $collectionTtl = $this->returnCollectionTtl($ttl); validateCacheName($cacheName); validateDictionaryName($dictionaryName); validateItems($items); validateFieldsKeys($items); - $ttlMillis = $this->ttlToMillis($ttlSeconds); + $ttlMillis = $this->ttlToMillis($collectionTtl->getTtl()); $protoItems = []; foreach ($items as $field => $value) { $fieldValuePair = new _DictionaryFieldValuePair(); @@ -558,7 +572,7 @@ public function dictionarySetFields(string $cacheName, string $dictionaryName, a } $dictionarySetFieldsRequest = new _DictionarySetRequest(); $dictionarySetFieldsRequest->setDictionaryName($dictionaryName); - $dictionarySetFieldsRequest->setRefreshTtl($refreshTtl); + $dictionarySetFieldsRequest->setRefreshTtl($collectionTtl->getRefreshTtl()); $dictionarySetFieldsRequest->setItems($protoItems); $dictionarySetFieldsRequest->setTtlMilliseconds($ttlMillis); $call = $this->grpcManager->client->DictionarySet($dictionarySetFieldsRequest, ["cache" => [$cacheName]], ["timeout" => $this->timeout]); @@ -595,21 +609,22 @@ public function dictionaryGetFields(string $cacheName, string $dictionaryName, a } public function dictionaryIncrement( - string $cacheName, string $dictionaryName, string $field, int $amount = 1, ?bool $refreshTtl = true, ?int $ttlSeconds = null + string $cacheName, string $dictionaryName, string $field, int $amount = 1, CollectionTtl $ttl = null ): CacheDictionaryIncrementResponse { try { + $collectionTtl = $this->returnCollectionTtl($ttl); validateCacheName($cacheName); validateDictionaryName($dictionaryName); validateFieldName($field); - $ttlMillis = $this->ttlToMillis($ttlSeconds); + $ttlMillis = $this->ttlToMillis($collectionTtl->getTtl()); validateTtl($ttlMillis); $dictionaryIncrementRequest = new _DictionaryIncrementRequest(); $dictionaryIncrementRequest ->setDictionaryName($dictionaryName) ->setField($field) ->setAmount($amount) - ->setRefreshTtl($refreshTtl) + ->setRefreshTtl($collectionTtl->getRefreshTtl()) ->setTtlMilliseconds($ttlMillis); $call = $this->grpcManager->client->DictionaryIncrement( $dictionaryIncrementRequest, ["cache" => [$cacheName]], ["timeout" => $this->timeout] diff --git a/src/Requests/CollectionTtl.php b/src/Requests/CollectionTtl.php new file mode 100644 index 00000000..cfd5880a --- /dev/null +++ b/src/Requests/CollectionTtl.php @@ -0,0 +1,46 @@ +ttl = $ttl; + $this->refreshTtl = $refreshTtl; + } + + public static function fromCacheTtl(): CollectionTtl + { + return new CollectionTtl(null, true); + } + + public static function of(int $ttl): CollectionTtl + { + return new CollectionTtl($ttl); + } + + public function getTtl(): int|null + { + return $this->ttl; + } + + public function getRefreshTtl(): bool|null + { + return $this->refreshTtl; + } + + public function withRefreshTtlOnUpdates(): CollectionTtl + { + return new CollectionTtl($this->ttl, $this->refreshTtl); + } + + public function withNoRefreshTtlOnUpdates(): CollectionTtl + { + return new CollectionTtl($this->ttl, false); + } +} diff --git a/tests/Cache/CacheClientTest.php b/tests/Cache/CacheClientTest.php index 07182e65..fd3d7590 100644 --- a/tests/Cache/CacheClientTest.php +++ b/tests/Cache/CacheClientTest.php @@ -15,6 +15,8 @@ use Momento\Config\Transport\StaticGrpcConfiguration; use Momento\Config\Transport\StaticTransportStrategy; use Momento\Logging\NullLoggerFactory; +use Momento\Requests\CollectionTtl; +use Momento\Requests\CollectionTtlFactory; use PHPUnit\Framework\TestCase; use RuntimeException; use TypeError; @@ -494,7 +496,7 @@ public function testListPushFrontFetchHappyPath() $listName = uniqid(); $value = uniqid(); $value2 = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttlSeconds: 6000); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::of(6000)); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(1, $response->asSuccess()->listLength()); @@ -507,7 +509,7 @@ public function testListPushFrontFetchHappyPath() $this->assertCount(1, $values); $this->assertContains($value, $values); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value2, ttlSeconds: 6000); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value2, ttl: CollectionTtl::of(6000)); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(2, $response->asSuccess()->listLength()); @@ -524,11 +526,11 @@ public function testListPushFront_NoRefreshTtl() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false, ttlSeconds: 5); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::of(5)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false, ttlSeconds: 10); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::of(10)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -542,11 +544,11 @@ public function testListPushFront_RefreshTtl() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false, ttlSeconds: 2); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::of(2)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttlSeconds: 10); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::of(10)->withRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -563,15 +565,15 @@ public function testListPushFront_TruncateList() $value1 = uniqid(); $value2 = uniqid(); $value3 = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value1, refreshTtl: false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value1, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value2, refreshTtl: false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value2, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value3, 2, false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value3, 2, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -585,7 +587,7 @@ public function testListPushFront_TruncateList_NegativeValue() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, -1, false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, -1, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNotNull($response->asError(), "Expected error but got: $response"); $this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode()); } @@ -595,7 +597,7 @@ public function testListPushBackFetchHappyPath() $listName = uniqid(); $value = uniqid(); $value2 = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttlSeconds: 6000); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::of(6000)); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(1, $response->asSuccess()->listLength()); @@ -608,7 +610,7 @@ public function testListPushBackFetchHappyPath() $this->assertCount(1, $values); $this->assertContains($value, $values); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value2, ttlSeconds: 6000); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value2, ttl: CollectionTtl::of(6000)); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(2, $response->asSuccess()->listLength()); @@ -625,11 +627,11 @@ public function testListPushBack_NoRefreshTtl() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false, ttlSeconds: 5); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::of(5)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false, ttlSeconds: 10); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::of(10)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -643,11 +645,11 @@ public function testListPushBack_RefreshTtl() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false, ttlSeconds: 2); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::of(2)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttlSeconds: 10); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::of(10)); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -664,15 +666,15 @@ public function testListPushBack_TruncateList() $value1 = uniqid(); $value2 = uniqid(); $value3 = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value1, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value1, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value2, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value2, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value3, 2, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value3, 2, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -686,7 +688,7 @@ public function testListPushBack_TruncateList_NegativeValue() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, -1, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, -1, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNotNull($response->asError(), "Expected error but got: $response"); $this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode()); } @@ -705,7 +707,7 @@ public function testListPopFront_HappyPath() $values = []; foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $val, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); array_unshift($values, $val); @@ -735,7 +737,7 @@ public function testListPopFront_EmptyList() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -760,7 +762,7 @@ public function testListPopBack_HappyPath() $values = []; foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $values[] = $val; @@ -783,7 +785,7 @@ public function testListPopBack_EmptyList() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -809,16 +811,16 @@ public function testListRemoveValue_HappyPath() $valueToRemove = uniqid(); foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $values[] = $val; } - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $valueToRemove, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $valueToRemove, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $valueToRemove, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $valueToRemove, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -845,7 +847,7 @@ public function testListRemoveValues_ValueNotPresent() $values = []; foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $values[] = $val; @@ -871,7 +873,7 @@ public function testListLength_HappyPath() $listName = uniqid(); foreach (range(0, 3) as $i) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -897,7 +899,7 @@ public function testListEraseAll_HappyPath() $listName = uniqid(); foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); } @@ -923,7 +925,7 @@ public function testListEraseRange_HappyPath() $values = []; foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $values[] = $val; @@ -950,7 +952,7 @@ public function testListEraseRange_LargeCountValue() $values = []; foreach (range(0, 3) as $ignored) { $val = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $val, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $values[] = $val; @@ -1060,7 +1062,7 @@ public function testDictionaryEmptyValue_IsError() $dictionaryName = uniqid(); $field = uniqid(); $value = ""; - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNotNull($response->asError(), "Expected error but got: $response"); $this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode()); } @@ -1070,11 +1072,11 @@ public function testDictionaryRefreshTtl() $dictionaryName = uniqid(); $field = uniqid(); $value = uniqid(); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, false, 2); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, ttl: CollectionTtl::of(2)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, ttlSeconds: 10); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, ttl: CollectionTtl::of(10)); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1106,7 +1108,7 @@ public function testDictionaryDelete_HappyPath() { $dictionaryName = uniqid(); $field = uniqid(); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, uniqid(), false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, uniqid(), ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1126,7 +1128,7 @@ public function testDictionaryIncrement_NullFieldError() { $dictionaryName = uniqid(); $field = ""; - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, refreshTtl: false); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNotNull($response->asError(), "Expected error but got: $response"); $this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode()); } @@ -1135,17 +1137,17 @@ public function testDictionaryIncrement_HappyPath() { $dictionaryName = uniqid(); $field = uniqid(); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, refreshTtl: false); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(1, $response->asSuccess()->valueInt()); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 41, refreshTtl: false); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 41, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(42, $response->asSuccess()->valueInt()); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: -1042, refreshTtl: false); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: -1042, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(-1000, $response->asSuccess()->valueInt()); @@ -1160,11 +1162,11 @@ public function testDictionaryIncrement_RefreshTtl() { $dictionaryName = uniqid(); $field = uniqid(); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, refreshTtl: false, ttlSeconds: 2); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, ttl: CollectionTtl::of(2)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, ttlSeconds: 10); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, ttl: CollectionTtl::of(10)); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(2); @@ -1179,11 +1181,11 @@ public function testDictionaryIncrement_NoRefreshTtl() { $dictionaryName = uniqid(); $field = uniqid(); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, refreshTtl: false, ttlSeconds: 5); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, ttl: CollectionTtl::of(5)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, refreshTtl: false, ttlSeconds: 10); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, ttl: CollectionTtl::of(10)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(6); @@ -1201,12 +1203,12 @@ public function testDictionaryIncrement_SetAndReset() $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 0, refreshTtl: false); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 0, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(10, $response->asSuccess()->valueInt()); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 90, refreshTtl: false); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 90, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(100, $response->asSuccess()->valueInt()); @@ -1215,7 +1217,7 @@ public function testDictionaryIncrement_SetAndReset() $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 0, refreshTtl: false); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 0, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(0, $response->asSuccess()->valueInt()); @@ -1225,7 +1227,7 @@ public function testDictionaryIncrement_FailedPrecondition() { $dictionaryName = uniqid(); $field = uniqid(); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, "amcaface", false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, "amcaface", CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1260,7 +1262,7 @@ public function testDictionaryRemoveField_HappyPath() $this->assertNull($response->asError()); $this->assertNotNull($response->asMiss(), "Expected a miss but got: $response"); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field1, $value1, false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field1, $value1, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1306,11 +1308,11 @@ public function testDictionaryRemoveFields_HappyPath() $fields = [uniqid(), uniqid()]; $otherField = uniqid(); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $fields[0], uniqid(), false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $fields[0], uniqid(), CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $fields[1], uniqid(), false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $fields[1], uniqid(), CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $otherField, uniqid(), false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $otherField, uniqid(), CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $response = $this->client->dictionaryRemoveFields($this->TEST_CACHE_NAME, $dictionaryName, $fields); @@ -1360,10 +1362,10 @@ public function testDictionaryFetch_HappyPath() $value1 = uniqid(); $value2 = uniqid(); $contentDictionary = [$field1 => $value1, $field2 => $value2]; - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field1, $value1, ttlSeconds: 10); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field1, $value1, CollectionTtl::of(10)); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field2, $value2, ttlSeconds: 10); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field2, $value2, CollectionTtl::of(10)); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1392,15 +1394,15 @@ public function testDictionaryFetchDictionaryDoesNotExist_Noop() public function testDictionaryDeleteDictionaryExists_HappyPath() { $dictionaryName = uniqid(); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, uniqid(), uniqid(), false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, uniqid(), uniqid(), CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, uniqid(), uniqid(), false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, uniqid(), uniqid(), CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, uniqid(), uniqid(), false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, uniqid(), uniqid(), CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1422,14 +1424,14 @@ public function testDictionarySetFieldsWithNullDictionaryName_ThrowsException() $this->expectException(TypeError::class); $dictionaryName = null; $items = [uniqid()]; - $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, false); + $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); } public function testDictionarySetFieldsWithEmptyDictionaryName_IsError() { $dictionaryName = ""; $items = [uniqid()]; - $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, false); + $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNotNull($response->asError(), "Expected error but got: $response"); $this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode()); } @@ -1439,19 +1441,19 @@ public function testDictionarySetFieldsWithNullItems_ThrowsException() $this->expectException(TypeError::class); $dictionaryName = uniqid(); $items = null; - $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, false); + $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); } public function testDictionarySetFieldsWithEmptyItems_IsError() { $dictionaryName = uniqid(); $items = [""]; - $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, false); + $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNotNull($response->asError(), "Expected error but got: $response"); $this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode()); $items = []; - $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, false); + $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNotNull($response->asError(), "Expected error but got: $response"); $this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode()); } @@ -1464,7 +1466,7 @@ public function testDictionarySetFields_HappyPath() $value1 = uniqid(); $value2 = uniqid(); $items = [$field1 => $value1, $field2 => $value2]; - $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, false, 10); + $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, CollectionTtl::of(10)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1485,11 +1487,11 @@ public function testDictionarySetFieldsRefreshTtl_HappyPath() $field = uniqid(); $value = uniqid(); $content = [$field => $value]; - $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $content, false, 2); + $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $content, CollectionTtl::of(2)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $content, ttlSeconds: 10); + $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $content, CollectionTtl::of(10)); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(2); @@ -1506,12 +1508,12 @@ public function testDictionarySetFieldsNoRefreshTtl_HappyPath() $field = uniqid(); $value = uniqid(); $content = [$field => $value]; - $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $content, false, 5); + $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $content, CollectionTtl::of(5)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(1); - $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $content, false, 10); + $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $content, CollectionTtl::of(10)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(4); @@ -1567,7 +1569,7 @@ public function testDictionaryGetFields_HappyPath() $value1 = uniqid(); $value2 = uniqid(); $items = [$field1 => $value1, $field2 => $value2]; - $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, false, 600); + $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, CollectionTtl::of(600)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1595,7 +1597,7 @@ public function testDictionaryGetBatchFieldsValuesArray_HappyPath() $value2 = uniqid(); $value3 = uniqid(); $items = [$field1 => $value1, $field2 => $value2, $field3 => $value3]; - $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, false, 10); + $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, CollectionTtl::of(10)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1625,7 +1627,7 @@ public function testDictionaryGetBatchFieldsValuesArray_MixedPath() $value1 = "val1"; $value3 = "val3"; $items = [$field1 => $value1, $field3 => $value3]; - $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, false, 10); + $response = $this->client->dictionarySetFields($this->TEST_CACHE_NAME, $dictionaryName, $items, CollectionTtl::of(10)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1685,7 +1687,7 @@ public function testCacheListPopFrontToString_HappyPath() { $listName = uniqid(); $value = "a short value"; - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $response = $this->client->listPopFront($this->TEST_CACHE_NAME, $listName); @@ -1697,7 +1699,7 @@ public function testCacheListPopFrontToString_LongValue() { $listName = uniqid(); $value = str_repeat("a", 256); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $response = $this->client->listPopFront($this->TEST_CACHE_NAME, $listName); @@ -1710,7 +1712,7 @@ public function testCacheListPopBackToString_HappyPath() { $listName = uniqid(); $value = "a short value"; - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $response = $this->client->listPopBack($this->TEST_CACHE_NAME, $listName); @@ -1722,7 +1724,7 @@ public function testCacheListPopBackToString_LongValue() { $listName = uniqid(); $value = str_repeat("a", 256); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $response = $this->client->listPopBack($this->TEST_CACHE_NAME, $listName); @@ -1735,11 +1737,11 @@ public function testCacheListFetchToString_HappyPath() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $response = $this->client->listFetch($this->TEST_CACHE_NAME, $listName); @@ -1752,13 +1754,13 @@ public function testCacheListPushFrontToString_HappyPath() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 1 items"); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 2 items"); - $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushFront($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl(2)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 3 items"); } @@ -1767,13 +1769,13 @@ public function testCacheListPushBackToString_HappyPath() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 1 items"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 2 items"); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 3 items"); } @@ -1782,11 +1784,11 @@ public function testCacheListLengthToString_HappyPath() { $listName = uniqid(); $value = uniqid(); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); - $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, refreshTtl: false); + $response = $this->client->listPushBack($this->TEST_CACHE_NAME, $listName, $value, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $response = $this->client->listLength($this->TEST_CACHE_NAME, $listName); @@ -1799,7 +1801,7 @@ public function testDictionaryGetFieldToString_HappyPath() $dictionaryName = uniqid(); $field = uniqid(); $value = uniqid(); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $response = $this->client->dictionaryGetField($this->TEST_CACHE_NAME, $dictionaryName, $field); @@ -1813,7 +1815,7 @@ public function testDictionaryGetFieldToString_LongValue() $dictionaryName = uniqid(); $field = uniqid(); $value = str_repeat("a", 256); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $response = $this->client->dictionaryGetField($this->TEST_CACHE_NAME, $dictionaryName, $field); @@ -1829,7 +1831,7 @@ public function testDictionaryFetchToString_HappyPath() $field = uniqid(); $value = uniqid(); for ($i = 0; $i < 5; $i++) { - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, "$field-$i", $value, false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, "$field-$i", $value, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); } $response = $this->client->dictionaryFetch($this->TEST_CACHE_NAME, $dictionaryName); @@ -1842,14 +1844,14 @@ public function testDictionaryIncrementToString_HappyPath() { $dictionaryName = uniqid(); $field = uniqid(); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, "1", false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, "1", CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, refreshTtl: false); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 2"); - $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 10, refreshTtl: false); + $response = $this->client->dictionaryIncrement($this->TEST_CACHE_NAME, $dictionaryName, $field, amount: 10, ttl: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertEquals("$response", get_class($response) . ": 12"); } @@ -1859,14 +1861,14 @@ public function testSetAddElementWithNullCacheName_ThrowsException() $this->expectException(TypeError::class); $setName = uniqid(); $element = uniqid(); - $this->client->setAddElement(null, $setName, $element, false); + $this->client->setAddElement(null, $setName, $element, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); } public function testSetAddElementWithEmptyCacheName_ThrowsException() { $setName = uniqid(); $element = uniqid(); - $response = $this->client->setAddElement("", $setName, $element, false); + $response = $this->client->setAddElement("", $setName, $element, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNotNull($response->asError(), "Expected error but got: $response"); $this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode()); } @@ -1875,13 +1877,13 @@ public function testSetAddElementWithNullSetName_ThrowsException() { $this->expectException(TypeError::class); $element = uniqid(); - $this->client->setAddElement($this->TEST_CACHE_NAME, null, $element, false); + $this->client->setAddElement($this->TEST_CACHE_NAME, null, $element, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); } public function testSetAddElementWithEmptySetName_ThrowsException() { $element = uniqid(); - $response = $this->client->setAddElement($this->TEST_CACHE_NAME, "", $element, false); + $response = $this->client->setAddElement($this->TEST_CACHE_NAME, "", $element, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNotNull($response->asError(), "Expected error but got: $response"); $this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode()); } @@ -1890,13 +1892,13 @@ public function testSetAddElementWithNullElement_ThrowsException() { $this->expectException(TypeError::class); $setName = uniqid(); - $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, null, false); + $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, null, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); } public function testSetAddElementWithEmptyElement_ThrowsException() { $setName = uniqid(); - $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, "", false); + $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, "", CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNotNull($response->asError(), "Expected error but got: $response"); $this->assertEquals(MomentoErrorCode::INVALID_ARGUMENT_ERROR, $response->asError()->errorCode()); } @@ -1933,7 +1935,7 @@ public function testSetAddElementSetFetch_HappyPath() { $setName = uniqid(); $element = uniqid(); - $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, false); + $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1947,12 +1949,12 @@ public function testSetAddElementSetFetch_NoRefreshTtl() { $setName = uniqid(); $element = uniqid(); - $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, false, 5); + $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, CollectionTtl::of(5)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(1); - $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, false, 10); + $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, CollectionTtl::of(10)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(4); @@ -1966,11 +1968,11 @@ public function testSetAddElementSetFetch_RefreshTtl() { $setName = uniqid(); $element = uniqid(); - $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, false, 2); + $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, CollectionTtl::of(2)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); - $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, ttlSeconds: 10); + $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, CollectionTtl::of(10)); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(2); @@ -2031,7 +2033,7 @@ public function testSetRemoveElement_HappyPath() { $setName = uniqid(); $element = uniqid(); - $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, false); + $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, $element, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -2108,13 +2110,13 @@ public function testSetDelete_SetDoesNotExist_Noop() public function testSetDelete_SetExists_HappyPath() { $setName = uniqid(); - $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, uniqid(), false); + $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, uniqid(), CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got ${response}."); - $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, uniqid(), false); + $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, uniqid(), CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got ${response}."); - $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, uniqid(), false); + $response = $this->client->setAddElement($this->TEST_CACHE_NAME, $setName, uniqid(), CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got ${response}."); From 9be7921601055c8b5aee7f389145934889f4edba Mon Sep 17 00:00:00 2001 From: erikatharp Date: Mon, 28 Nov 2022 15:59:36 -0800 Subject: [PATCH 4/7] fix: use CollectionTtl in setAddElement and fix tests --- src/Cache/_ScsDataClient.php | 7 ++++--- tests/Cache/CacheClientTest.php | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Cache/_ScsDataClient.php b/src/Cache/_ScsDataClient.php index 79c657c0..c5d13316 100644 --- a/src/Cache/_ScsDataClient.php +++ b/src/Cache/_ScsDataClient.php @@ -684,17 +684,18 @@ public function dictionaryRemoveFields(string $cacheName, string $dictionaryName return new CacheDictionaryRemoveFieldsResponseSuccess(); } - public function setAddElement(string $cacheName, string $setName, string $element, ?bool $refreshTt = true, ?int $ttlSeconds = null): CacheSetAddElementResponse + public function setAddElement(string $cacheName, string $setName, string $element, CollectionTtl $ttl = null): CacheSetAddElementResponse { try { + $collectionTtl = $this->returnCollectionTtl($ttl); validateCacheName($cacheName); validateSetName($setName); validateElement($element); - $ttlMillis = $this->ttlToMillis($ttlSeconds); + $ttlMillis = $this->ttlToMillis($collectionTtl->getTtl()); validateTtl($ttlMillis); $setAddElementRequest = new _SetUnionRequest(); $setAddElementRequest->setSetName($setName); - $setAddElementRequest->setRefreshTtl($refreshTt); + $setAddElementRequest->setRefreshTtl($collectionTtl->getRefreshTtl()); $setAddElementRequest->setTtlMilliseconds($ttlMillis); $setAddElementRequest->setElements([$element]); $call = $this->grpcManager->client->SetUnion($setAddElementRequest, ["cache" => [$cacheName]], ["timeout" => $this->timeout]); diff --git a/tests/Cache/CacheClientTest.php b/tests/Cache/CacheClientTest.php index fd3d7590..e5270861 100644 --- a/tests/Cache/CacheClientTest.php +++ b/tests/Cache/CacheClientTest.php @@ -995,7 +995,7 @@ public function testDictionary_HappyPath() $dictionaryName = uniqid(); $field = uniqid(); $value = uniqid(); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1009,7 +1009,7 @@ public function testDictionaryFieldMissing() $dictionaryName = uniqid(); $field = uniqid(); $value = uniqid(); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1024,12 +1024,12 @@ public function testDictionaryNoRefreshTtl() $dictionaryName = uniqid(); $field = uniqid(); $value = uniqid(); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, false, 5); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, CollectionTtl::of(5)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(1); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, false, 10); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, $value, CollectionTtl::of(10)->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); sleep(4); From 2e8af3a52dd51ae16e7784db20863e4242e6ee5b Mon Sep 17 00:00:00 2001 From: erikatharp Date: Mon, 28 Nov 2022 16:06:01 -0800 Subject: [PATCH 5/7] fix: CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates() --- tests/Cache/CacheClientTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Cache/CacheClientTest.php b/tests/Cache/CacheClientTest.php index e5270861..d8e53f6e 100644 --- a/tests/Cache/CacheClientTest.php +++ b/tests/Cache/CacheClientTest.php @@ -1199,7 +1199,7 @@ public function testDictionaryIncrement_SetAndReset() { $dictionaryName = uniqid(); $field = uniqid(); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, "10", false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, "10", CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); @@ -1213,7 +1213,7 @@ public function testDictionaryIncrement_SetAndReset() $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); $this->assertEquals(100, $response->asSuccess()->valueInt()); - $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, "0", false); + $response = $this->client->dictionarySetField($this->TEST_CACHE_NAME, $dictionaryName, $field, "0", CollectionTtl::fromCacheTtl()->withNoRefreshTtlOnUpdates()); $this->assertNull($response->asError()); $this->assertNotNull($response->asSuccess(), "Expected a success but got: $response"); From d0dea01ecb8b958c8f159e1ba936a99a8f30a83b Mon Sep 17 00:00:00 2001 From: erikatharp Date: Tue, 29 Nov 2022 10:28:12 -0800 Subject: [PATCH 6/7] chore: add type for returnCollectionTtl arg and update nate to include unit for ttl --- src/Cache/SimpleCacheClient.php | 1 - src/Cache/_ScsDataClient.php | 2 +- src/Requests/CollectionTtl.php | 12 ++++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Cache/SimpleCacheClient.php b/src/Cache/SimpleCacheClient.php index a4d8a9cf..8558fd15 100644 --- a/src/Cache/SimpleCacheClient.php +++ b/src/Cache/SimpleCacheClient.php @@ -33,7 +33,6 @@ use Momento\Config\IConfiguration; use Momento\Logging\ILoggerFactory; use Momento\Requests\CollectionTtl; -use Momento\Requests\CollectionTtlFactory; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; diff --git a/src/Cache/_ScsDataClient.php b/src/Cache/_ScsDataClient.php index c5d13316..90b4d3b2 100644 --- a/src/Cache/_ScsDataClient.php +++ b/src/Cache/_ScsDataClient.php @@ -177,7 +177,7 @@ private function ttlToMillis(?int $ttl = null): int return $ttl * 1000; } - private function returnCollectionTtl($ttl): CollectionTtl + private function returnCollectionTtl(?CollectionTtl $ttl): CollectionTtl { if (!$ttl) { return CollectionTtl::fromCacheTtl(); diff --git a/src/Requests/CollectionTtl.php b/src/Requests/CollectionTtl.php index cfd5880a..b1ece063 100644 --- a/src/Requests/CollectionTtl.php +++ b/src/Requests/CollectionTtl.php @@ -5,12 +5,12 @@ class CollectionTtl { - private ?int $ttl; + private ?int $ttlSeconds; private ?bool $refreshTtl; - public function __construct(?int $ttl = null, ?bool $refreshTtl = true) + public function __construct(?int $ttlSeconds = null, ?bool $refreshTtl = true) { - $this->ttl = $ttl; + $this->ttlSeconds = $ttlSeconds; $this->refreshTtl = $refreshTtl; } @@ -26,7 +26,7 @@ public static function of(int $ttl): CollectionTtl public function getTtl(): int|null { - return $this->ttl; + return $this->ttlSeconds; } public function getRefreshTtl(): bool|null @@ -36,11 +36,11 @@ public function getRefreshTtl(): bool|null public function withRefreshTtlOnUpdates(): CollectionTtl { - return new CollectionTtl($this->ttl, $this->refreshTtl); + return new CollectionTtl($this->ttlSeconds, $this->refreshTtl); } public function withNoRefreshTtlOnUpdates(): CollectionTtl { - return new CollectionTtl($this->ttl, false); + return new CollectionTtl($this->ttlSeconds, false); } } From 4f987c0d444a23fe99a87b17f245b456a1b3f906 Mon Sep 17 00:00:00 2001 From: erikatharp Date: Fri, 2 Dec 2022 11:22:56 -0800 Subject: [PATCH 7/7] chore: make CollectionTtl param type explicitly nullable by updating to ?CollectionTtl; chore: rename of param to --- src/Cache/SimpleCacheClient.php | 12 ++++++------ src/Cache/_ScsDataClient.php | 12 ++++++------ src/Requests/CollectionTtl.php | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Cache/SimpleCacheClient.php b/src/Cache/SimpleCacheClient.php index 8558fd15..bcafdb6a 100644 --- a/src/Cache/SimpleCacheClient.php +++ b/src/Cache/SimpleCacheClient.php @@ -106,14 +106,14 @@ public function listFetch(string $cacheName, string $listName): CacheListFetchRe } public function listPushFront( - string $cacheName, string $listName, string $value, ?int $truncateBackToSize = null, CollectionTtl $ttl = null + string $cacheName, string $listName, string $value, ?int $truncateBackToSize = null, ?CollectionTtl $ttl = null ): CacheListPushFrontResponse { return $this->dataClient->listPushFront($cacheName, $listName, $value, $truncateBackToSize, $ttl); } public function listPushBack( - string $cacheName, string $listName, string $value, ?int $truncateFrontToSize = null, CollectionTtl $ttl = null + string $cacheName, string $listName, string $value, ?int $truncateFrontToSize = null, ?CollectionTtl $ttl = null ): CacheListPushBackResponse { return $this->dataClient->listPushBack($cacheName, $listName, $value, $truncateFrontToSize, $ttl); @@ -144,7 +144,7 @@ public function listErase(string $cacheName, string $listName, ?int $beginIndex return $this->dataClient->listErase($cacheName, $listName, $beginIndex, $count); } - public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, CollectionTtl $ttl = null): CacheDictionarySetFieldResponse + public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, ?CollectionTtl $ttl = null): CacheDictionarySetFieldResponse { return $this->dataClient->dictionarySetField($cacheName, $dictionaryName, $field, $value, $ttl); } @@ -164,7 +164,7 @@ public function dictionaryFetch(string $cacheName, string $dictionaryName): Cach return $this->dataClient->dictionaryFetch($cacheName, $dictionaryName); } - public function dictionarySetFields(string $cacheName, string $dictionaryName, array $items, CollectionTtl $ttl = null): CacheDictionarySetFieldsResponse + public function dictionarySetFields(string $cacheName, string $dictionaryName, array $items, ?CollectionTtl $ttl = null): CacheDictionarySetFieldsResponse { return $this->dataClient->dictionarySetFields($cacheName, $dictionaryName, $items, $ttl); } @@ -175,7 +175,7 @@ public function dictionaryGetFields(string $cacheName, string $dictionaryName, a } public function dictionaryIncrement( - string $cacheName, string $dictionaryName, string $field, int $amount = 1, CollectionTtl $ttl = null + string $cacheName, string $dictionaryName, string $field, int $amount = 1, ?CollectionTtl $ttl = null ): CacheDictionaryIncrementResponse { return $this->dataClient->dictionaryIncrement($cacheName, $dictionaryName, $field, $amount, $ttl); @@ -191,7 +191,7 @@ public function dictionaryRemoveFields(string $cacheName, string $dictionaryName return $this->dataClient->dictionaryRemoveFields($cacheName, $dictionaryName, $fields); } - public function setAddElement(string $cacheName, string $setName, string $element, CollectionTtl $ttl = null): CacheSetAddElementResponse + public function setAddElement(string $cacheName, string $setName, string $element, ?CollectionTtl $ttl = null): CacheSetAddElementResponse { return $this->dataClient->setAddElement($cacheName, $setName, $element, $ttl); } diff --git a/src/Cache/_ScsDataClient.php b/src/Cache/_ScsDataClient.php index 90b4d3b2..624ad579 100644 --- a/src/Cache/_ScsDataClient.php +++ b/src/Cache/_ScsDataClient.php @@ -281,7 +281,7 @@ public function listFetch(string $cacheName, string $listName): CacheListFetchRe } public function listPushFront( - string $cacheName, string $listName, string $value, ?int $truncateBackToSize = null, CollectionTtl $ttl = null + string $cacheName, string $listName, string $value, ?int $truncateBackToSize = null, ?CollectionTtl $ttl = null ): CacheListPushFrontResponse { try { @@ -311,7 +311,7 @@ public function listPushFront( } public function listPushBack( - string $cacheName, string $listName, string $value, ?int $truncateFrontToSize = null, CollectionTtl $ttl = null + string $cacheName, string $listName, string $value, ?int $truncateFrontToSize = null, ?CollectionTtl $ttl = null ): CacheListPushBackResponse { try { @@ -454,7 +454,7 @@ public function listErase(string $cacheName, string $listName, ?int $beginIndex return new CacheListEraseResponseSuccess(); } - public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, CollectionTtl $ttl = null): CacheDictionarySetFieldResponse + public function dictionarySetField(string $cacheName, string $dictionaryName, string $field, string $value, ?CollectionTtl $ttl = null): CacheDictionarySetFieldResponse { try { $collectionTtl = $this->returnCollectionTtl($ttl); @@ -554,7 +554,7 @@ public function dictionaryFetch(string $cacheName, string $dictionaryName): Cach return new CacheDictionaryFetchResponseMiss(); } - public function dictionarySetFields(string $cacheName, string $dictionaryName, array $items, CollectionTtl $ttl = null): CacheDictionarySetFieldsResponse + public function dictionarySetFields(string $cacheName, string $dictionaryName, array $items, ?CollectionTtl $ttl = null): CacheDictionarySetFieldsResponse { try { $collectionTtl = $this->returnCollectionTtl($ttl); @@ -609,7 +609,7 @@ public function dictionaryGetFields(string $cacheName, string $dictionaryName, a } public function dictionaryIncrement( - string $cacheName, string $dictionaryName, string $field, int $amount = 1, CollectionTtl $ttl = null + string $cacheName, string $dictionaryName, string $field, int $amount = 1, ?CollectionTtl $ttl = null ): CacheDictionaryIncrementResponse { try { @@ -684,7 +684,7 @@ public function dictionaryRemoveFields(string $cacheName, string $dictionaryName return new CacheDictionaryRemoveFieldsResponseSuccess(); } - public function setAddElement(string $cacheName, string $setName, string $element, CollectionTtl $ttl = null): CacheSetAddElementResponse + public function setAddElement(string $cacheName, string $setName, string $element, ?CollectionTtl $ttl = null): CacheSetAddElementResponse { try { $collectionTtl = $this->returnCollectionTtl($ttl); diff --git a/src/Requests/CollectionTtl.php b/src/Requests/CollectionTtl.php index b1ece063..1540bde5 100644 --- a/src/Requests/CollectionTtl.php +++ b/src/Requests/CollectionTtl.php @@ -19,9 +19,9 @@ public static function fromCacheTtl(): CollectionTtl return new CollectionTtl(null, true); } - public static function of(int $ttl): CollectionTtl + public static function of(int $ttlSeconds): CollectionTtl { - return new CollectionTtl($ttl); + return new CollectionTtl($ttlSeconds); } public function getTtl(): int|null