From c36812bb6174fb46320f1503c222e5d75a1ef00a Mon Sep 17 00:00:00 2001 From: JonPurvis Date: Mon, 24 Nov 2025 18:42:58 +0000 Subject: [PATCH 1/4] check for value in cache --- src/Stores/LaravelCacheStore.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Stores/LaravelCacheStore.php b/src/Stores/LaravelCacheStore.php index 27a0ddd..6d0df2a 100644 --- a/src/Stores/LaravelCacheStore.php +++ b/src/Stores/LaravelCacheStore.php @@ -32,6 +32,17 @@ public function get(string $key): ?string */ public function set(string $key, string $value, int $ttl): bool { - return $this->store->put($key, $value, $ttl); + $result = $this->store->put($key, $value, $ttl); + + // If the data already exists in the cache, then mysql returns 0 rows affected. Technically, this is not a + // failure. We should check for this before returning anything and return true if it does exist. + if ($result === false) { + $existingValue = $this->store->get($key); + if ($existingValue === $value) { + return true; + } + } + + return $result; } } From 038edfa8b5a828db0be6908f17fc90c565289362 Mon Sep 17 00:00:00 2001 From: JonPurvis Date: Mon, 24 Nov 2025 18:52:30 +0000 Subject: [PATCH 2/4] add test --- tests/Laravel/Feature/LaravelStoreTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/Laravel/Feature/LaravelStoreTest.php b/tests/Laravel/Feature/LaravelStoreTest.php index 777589d..b1c1685 100644 --- a/tests/Laravel/Feature/LaravelStoreTest.php +++ b/tests/Laravel/Feature/LaravelStoreTest.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use Illuminate\Contracts\Cache\Repository; use Saloon\RateLimitPlugin\Limit; use Illuminate\Support\Facades\Cache; use Saloon\RateLimitPlugin\Stores\LaravelCacheStore; @@ -37,3 +38,17 @@ 'hits' => 1, ])); }); + +test('it handles MySQL upsert behavior returning false for identical data', function () { + $mockCache = Mockery::mock(Repository::class); + + $key = 'test:limit'; + $value = json_encode(['timestamp' => time() + 60, 'hits' => 1]); + + $mockCache->shouldReceive('put')->with($key, $value, Mockery::any())->andReturn(false); + $mockCache->shouldReceive('get')->with($key)->andReturn($value); + + $store = new LaravelCacheStore($mockCache); + + expect($store->set($key, $value, 60))->toBeTrue(); +}); From f34a4ac11d1cb5f1707beadab8c19a365f6b2db2 Mon Sep 17 00:00:00 2001 From: Sammyjo20 <29132017+Sammyjo20@users.noreply.github.com> Date: Thu, 27 Nov 2025 21:17:47 +0000 Subject: [PATCH 3/4] Empty Commit From 15ca77162b334ee4f8ee473a2c943f0b238c6b50 Mon Sep 17 00:00:00 2001 From: Sammyjo20 <29132017+Sammyjo20@users.noreply.github.com> Date: Thu, 27 Nov 2025 21:18:37 +0000 Subject: [PATCH 4/4] Code fixes --- tests/Laravel/Feature/LaravelStoreTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Laravel/Feature/LaravelStoreTest.php b/tests/Laravel/Feature/LaravelStoreTest.php index b1c1685..82b4a41 100644 --- a/tests/Laravel/Feature/LaravelStoreTest.php +++ b/tests/Laravel/Feature/LaravelStoreTest.php @@ -2,9 +2,9 @@ declare(strict_types=1); -use Illuminate\Contracts\Cache\Repository; use Saloon\RateLimitPlugin\Limit; use Illuminate\Support\Facades\Cache; +use Illuminate\Contracts\Cache\Repository; use Saloon\RateLimitPlugin\Stores\LaravelCacheStore; test('it records and can check exceeded limits', function () {