Skip to content

Commit 5ecf8f1

Browse files
committed
Use the same lock for pruning and clearing
1 parent 3a090b0 commit 5ecf8f1

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/Psr6Store.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Psr6Store implements Psr6StoreInterface, ClearableInterface
4848
const NON_VARYING_KEY = 'non-varying';
4949
const COUNTER_KEY = 'write-operations-counter';
5050
const CACHE_DEBUG_HEADER = 'toflar-psr6cache-requested-uri';
51+
const CLEANUP_LOCK_KEY = 'cleanup-lock';
5152

5253
/**
5354
* @var array
@@ -371,8 +372,8 @@ public function prune()
371372
return;
372373
}
373374

374-
// Make sure we do not have multiple pruning processes running
375-
$lock = $this->lockFactory->createLock('prune-lock');
375+
// Make sure we do not have multiple clearing or pruning processes running
376+
$lock = $this->lockFactory->createLock(self::CLEANUP_LOCK_KEY);
376377

377378
if ($lock->acquire()) {
378379
$this->cache->prune();
@@ -386,8 +387,8 @@ public function prune()
386387
*/
387388
public function clear()
388389
{
389-
// Make sure we do not have multiple pruning processes running
390-
$lock = $this->lockFactory->createLock('clear-lock');
390+
// Make sure we do not have multiple clearing or pruning processes running
391+
$lock = $this->lockFactory->createLock(self::CLEANUP_LOCK_KEY);
391392

392393
if ($lock->acquire()) {
393394
$this->cache->clear();

tests/Psr6StoreTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ public function testAutoPruneExpiredEntries()
610610
$lockFactory
611611
->expects($this->any())
612612
->method('createLock')
613-
->with('prune-lock')
613+
->with(Psr6Store::CLEANUP_LOCK_KEY)
614614
->willReturn($lock);
615615

616616
$store = new Psr6Store([
@@ -679,7 +679,7 @@ public function testAutoPruneIsSkippedIfPruningIsAlreadyInProgress()
679679
$lockFactory
680680
->expects($this->any())
681681
->method('createLock')
682-
->with('prune-lock')
682+
->with(Psr6Store::CLEANUP_LOCK_KEY)
683683
->willReturn($lock);
684684

685685
$store = new Psr6Store([

0 commit comments

Comments
 (0)