diff --git a/composer.json b/composer.json index e6f114e..e950e77 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "illuminate/contracts": "11.*|12.*" }, "require-dev": { - "orchestra/testbench": "9.*|10.*" + "orchestra/testbench": "^9.16|10.*" }, "autoload": { "psr-4": { diff --git a/src/Proxy.php b/src/Proxy.php index 5afc7f4..ebd52a5 100644 --- a/src/Proxy.php +++ b/src/Proxy.php @@ -11,6 +11,7 @@ use Illuminate\Support\Str; use function app; +use function array_filter; use function array_shift; use function is_array; use function max; @@ -159,7 +160,11 @@ protected function retrieveResultsFromCache(string $key): array return [$key => null, $this->cache->key => null]; } - return $this->repository->getMultiple([$key, $this->cache->key]); + $result = $this->repository->getMultiple(array_filter([$key, $this->cache->key])); + + $result[$this->cache->key] ??= null; + + return $result; } /** diff --git a/tests/ProxyTest.php b/tests/ProxyTest.php index a13faec..f383f0c 100644 --- a/tests/ProxyTest.php +++ b/tests/ProxyTest.php @@ -370,7 +370,7 @@ public function test_uses_custom_time_to_live(): void $interval = $now->diffAsCarbonInterval(now()); $repository = $this->mock(Repository::class); - $repository->expects('getMultiple')->with([$hash, ''])->times(4)->andReturn(['' => null, $hash => null]); + $repository->expects('getMultiple')->with([$hash])->times(4)->andReturn(['' => null, $hash => null]); $repository->allows('getStore')->never(); $repository->expects('put')->with($hash, Mockery::type('array'), null); $repository->expects('put')->with($hash, Mockery::type('array'), $seconds); @@ -560,7 +560,7 @@ public function test_uses_custom_store(): void $repository = $this->mock(Repository::class); $repository->expects('flexible')->never(); $repository->expects('put')->with($hash, Mockery::type('array'), 60)->once(); - $repository->expects('getMultiple')->with([$hash, ''])->times(1)->andReturn(['' => null, $hash => null]); + $repository->expects('getMultiple')->with([$hash])->times(1)->andReturn(['' => null, $hash => null]); $this->mock('cache')->expects('store')->with('test-store')->andReturn($repository); @@ -630,7 +630,7 @@ public function test_doesnt_uses_flexible_caching_if_repository_is_not_flexible( $repository = $this->mock(Repository::class); $repository->expects('flexible')->never(); $repository->expects('put')->with($hash, Mockery::type('array'), [5, 300])->once(); - $repository->expects('getMultiple')->with([$hash, ''])->times(1)->andReturn(['' => null, $hash => null]); + $repository->expects('getMultiple')->with([$hash])->times(1)->andReturn(['' => null, $hash => null]); $this->mock('cache')->expects('store')->with(null)->andReturn($repository); @@ -921,7 +921,7 @@ public function test_base_query_uses_cache_callback(): void $repository = $this->mock(Repository::class); $repository->expects('flexible')->never(); $repository->expects('put')->with($hash, Mockery::type('array'), [5, 300])->once(); - $repository->expects('getMultiple')->with([$hash, ''])->times(1)->andReturn(['' => null, $hash => null]); + $repository->expects('getMultiple')->with([$hash])->times(1)->andReturn(['' => null, $hash => null]); $this->mock('cache')->expects('store')->with(null)->andReturn($repository);