Skip to content

Commit 6d0d2f5

Browse files
minor #46004 [Cache] make LockRegistry use static properties instead of static variables (mrsuh)
This PR was submitted for the 5.4 branch but it was merged into the 4.4 branch instead. Discussion ---------- [Cache] make LockRegistry use static properties instead of static variables | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #44954 | License | MIT Commits ------- 3b6a56d [Cache] make LockRegistry use static properties instead of static variables
2 parents 6af4986 + 3b6a56d commit 6d0d2f5

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Symfony/Component/Cache/LockRegistry.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ final class LockRegistry
2828
{
2929
private static $openedFiles = [];
3030
private static $lockedFiles;
31+
private static $signalingException;
32+
private static $signalingCallback;
3133

3234
/**
3335
* The number of items in this list controls the max number of concurrent processes.
@@ -92,6 +94,9 @@ public static function compute(callable $callback, ItemInterface $item, bool &$s
9294
return $callback($item, $save);
9395
}
9496

97+
self::$signalingException ?? self::$signalingException = unserialize("O:9:\"Exception\":1:{s:16:\"\0Exception\0trace\";a:0:{}}");
98+
self::$signalingCallback ?? self::$signalingCallback = function () { throw self::$signalingException; };
99+
95100
while (true) {
96101
try {
97102
// race to get the lock in non-blocking mode
@@ -121,18 +126,15 @@ public static function compute(callable $callback, ItemInterface $item, bool &$s
121126
flock($lock, \LOCK_UN);
122127
unset(self::$lockedFiles[$key]);
123128
}
124-
static $signalingException, $signalingCallback;
125-
$signalingException = $signalingException ?? unserialize("O:9:\"Exception\":1:{s:16:\"\0Exception\0trace\";a:0:{}}");
126-
$signalingCallback = $signalingCallback ?? function () use ($signalingException) { throw $signalingException; };
127129

128130
try {
129-
$value = $pool->get($item->getKey(), $signalingCallback, 0);
131+
$value = $pool->get($item->getKey(), self::$signalingCallback, 0);
130132
$logger && $logger->info('Item "{key}" retrieved after lock was released', ['key' => $item->getKey()]);
131133
$save = false;
132134

133135
return $value;
134136
} catch (\Exception $e) {
135-
if ($signalingException !== $e) {
137+
if (self::$signalingException !== $e) {
136138
throw $e;
137139
}
138140
$logger && $logger->info('Item "{key}" not found while lock was released, now retrying', ['key' => $item->getKey()]);

src/Symfony/Component/Cache/Traits/ContractsTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ trait ContractsTrait
4242
public function setCallbackWrapper(?callable $callbackWrapper): callable
4343
{
4444
if (!isset($this->callbackWrapper)) {
45-
$this->callbackWrapper = [LockRegistry::class, 'compute'];
45+
$this->callbackWrapper = \Closure::fromCallable([LockRegistry::class, 'compute']);;
4646

4747
if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
4848
$this->setCallbackWrapper(null);

0 commit comments

Comments
 (0)