8000 [Cache] disable lock on CLI · symfony/symfony@15f5e09 · GitHub
[go: up one dir, main page]

Skip to content

Commit 15f5e09

Browse files
[Cache] disable lock on CLI
1 parent d6710c1 commit 15f5e09

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Symfony\Component\Cache\Adapter\ArrayAdapter;
2020
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
2121
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
22-
use Symfony\Component\Cache\LockRegistry;
2322
use Symfony\Component\Cache\Tests\Fixtures\PrunableAdapter;
2423

2524
/**
@@ -198,24 +197,6 @@ public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemAndOnlyHasTags
198197
$this->assertFalse($item->isHit());
199198
}
200199

201-
public function testLog()
202-
{
203-
$lockFiles = LockRegistry::setFiles([__FILE__]);
204-
205-
$logger = $this->createMock(LoggerInterface::class);
206-
$logger
207-
->expects($this->atLeastOnce())
208-
->method($this->anything());
209-
210-
$cache = new TagAwareAdapter(new ArrayAdapter());
211-
$cache->setLogger($logger);
212-
213-
// Computing will produce at least one log
214-
$cache->get('foo', static function (): string { return 'ccc'; });
215-
216-
LockRegistry::setFiles($lockFiles);
217-
}
218-
219200
/**
220201
* @return MockObject&PruneableCacheInterface
221202
*/

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ trait ContractsTrait
3131
doGet as private contractsGet;
3232
}
3333

34-
private $callbackWrapper = [LockRegistry::class, 'compute'];
34+
private $callbackWrapper;
3535
private $computing = [];
3636

3737
/**
@@ -41,8 +41,16 @@ trait ContractsTrait
4141
*/
4242
public function setCallbackWrapper(?callable $callbackWrapper): callable
4343
{
44+
if (!isset($this->callbackWrapper)) {
45+
$this->callbackWrapper = \Closure::fromCallable([LockRegistry::class, 'compute']);
46+
47+
if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
48+
$this->setCallbackWrapper(null);
49+
}
50+
}
51+
4452
$previousWrapper = $this->callbackWrapper;
45-
$this->callbackWrapper = $callbackWrapper ?? function (callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool, \Closure $setMetadata, ?LoggerInterface $logger) {
53+
$this->callbackWrapper = $callbackWrapper ?? static function (callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool, \Closure $setMetadata, ?LoggerInterface $logger) {
4654
return $callback($item, $save);
4755
};
4856

@@ -82,6 +90,10 @@ static function (CacheItem $item, float $startTime, ?array &$metadata) {
8290
$this->computing[$key] = $key;
8391
$startTime = microtime(true);
8492

93+
if (!isset($this->callbackWrapper)) {
94+
$this->setCallbackWrapper($this->setCallbackWrapper(null));
95+
}
96+
8597
try {
8698
$value = ($this->callbackWrapper)($callback, $item, $save, $pool, function (CacheItem $item) use ($setMetadata, $startTime, &$metadata) {
8799
$setMetadata($item, $startTime, $metadata);

0 commit comments

Comments
 (0)
0