Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/Stache/Stache.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Stache
protected $lockFactory;
protected $locks = [];
protected $duplicates;
protected $exclude = [];

public function __construct()
{
Expand Down Expand Up @@ -60,6 +61,13 @@ public function registerStores($stores)
return $this;
}

public function exclude(string $store)
{
$this->exclude[] = $store;

return $this;
}

public function stores()
{
return $this->stores;
Expand Down Expand Up @@ -88,7 +96,7 @@ public function generateId()

public function clear()
{
$this->stores()->reverse()->each->clear();
$this->stores()->except($this->exclude)->reverse()->each->clear();

$this->duplicates()->clear();

Expand All @@ -110,7 +118,7 @@ public function warm()

$this->startTimer();

$this->stores()->each->warm();
$this->stores()->except($this->exclude)->each->warm();

$this->stopTimer();

Expand Down
25 changes: 25 additions & 0 deletions tests/Stache/StacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use Illuminate\Support\Collection;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Stache\NullLockStore;
use Statamic\Stache\Stache;
use Statamic\Stache\Stores\ChildStore;
use Statamic\Stache\Stores\CollectionsStore;
use Statamic\Stache\Stores\EntriesStore;
use Symfony\Component\Lock\LockFactory;
use Tests\TestCase;

class StacheTest extends TestCase
Expand Down Expand Up @@ -61,6 +63,29 @@ public function stores_can_be_registered()
});
}

#[Test]
public function stores_can_be_excluded_from_warming_and_clearing()
{
$this->stache->sites(['en']); // store expects the stache to have site(s)
$this->assertTrue($this->stache->stores()->isEmpty());

$mockStore = $this->mock(CollectionsStore::class, function ($mock) {
$mock->shouldReceive('warm')->never();
$mock->shouldReceive('clear')->never();
$mock->shouldReceive('key')->andReturn('collections');
});

$this->stache->registerStore($mockStore);

$return = $this->stache->exclude('collections');

$this->assertEquals($this->stache, $return);

$this->stache->setLockFactory(new LockFactory(new NullLockStore()));
$this->stache->warm();
$this->stache->clear();
}

#[Test]
public function multiple_stores_can_be_registered_at_once()
{
Expand Down