Skip to content

Commit b968514

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

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
use PHPUnit\Framework\MockObject\MockObject;
1515
use Psr\Cache\CacheItemInterface;
1616
use Psr\Cache\CacheItemPoolInterface;
17-
use Psr\Log\LoggerInterface;
1817
use Symfony\Component\Cache\Adapter\AdapterInterface;
1918
use Symfony\Component\Cache\Adapter\ArrayAdapter;
2019
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
2120
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
22-
use Symfony\Component\Cache\LockRegistry;
2321
use Symfony\Component\Cache\Tests\Fixtures\PrunableAdapter;
2422

2523
/**
@@ -198,24 +196,6 @@ public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemAndOnlyHasTags
198196
$this->assertFalse($item->isHit());
199197
}
200198

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-
219199
/**
220200
* @return MockObject&PruneableCacheInterface
221201
*/

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy