Skip to content

Commit

Permalink
Merge pull request #205 from jonnyka/cachecheck-racecondition-fix
Browse files Browse the repository at this point in the history
Fixed the CacheCheck causing race conditions in some cases
  • Loading branch information
freekmurze authored Dec 5, 2023
2 parents f7fc30c + 48ffec9 commit 4e4ab00
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Checks/Checks/CacheCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ protected function canWriteValuesToCache(?string $driver): bool
{
$expectedValue = Str::random(5);

Cache::driver($driver)->put('laravel-health:check', $expectedValue, 10);
$cacheName = "laravel-health:check-{$expectedValue}";

$actualValue = Cache::driver($driver)->get('laravel-health:check');
Cache::driver($driver)->put($cacheName, $expectedValue, 10);

$actualValue = Cache::driver($driver)->get($cacheName);

Cache::driver($driver)->forget($cacheName);

return $actualValue === $expectedValue;
}
Expand Down

0 comments on commit 4e4ab00

Please sign in to comment.