From 024c5148771885db7b2b88041104ba64df858b3a Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Fri, 12 Apr 2024 20:40:57 -0400 Subject: [PATCH] Remove cache:clearing hook. --- CHANGELOG.md | 4 ++++ src/LaravelDDDServiceProvider.php | 2 -- tests/Command/CacheTest.php | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aaa0d6..186bc85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `laravel-ddd` will be documented in this file. +## [Unversioned] +### Changed +- Internal: Domain cache is no longer quietly cleared on laravel's `cache:clearing` event, so that `ddd:cache` yields consistent results regardless of being executed before or after `cache:clear` or `optimize:clear` commands. + ## [1.1.0] - 2024-04-07 ### Added - Add `ddd:class` generator extending Laravel's `make:class` (Laravel 11 only). diff --git a/src/LaravelDDDServiceProvider.php b/src/LaravelDDDServiceProvider.php index 19f6de2..f804c55 100644 --- a/src/LaravelDDDServiceProvider.php +++ b/src/LaravelDDDServiceProvider.php @@ -69,7 +69,5 @@ public function packageBooted() public function packageRegistered() { (new DomainAutoloader())->autoload(); - - Event::subscribe(CacheClearSubscriber::class); } } diff --git a/tests/Command/CacheTest.php b/tests/Command/CacheTest.php index 029e4c2..33835d0 100644 --- a/tests/Command/CacheTest.php +++ b/tests/Command/CacheTest.php @@ -40,3 +40,23 @@ expect(DomainCache::get('domain-providers'))->toBeNull(); expect(DomainCache::get('domain-commands'))->toBeNull(); }); + +it('will not be cleared by laravel cache clearing', function () { + expect(DomainCache::get('domain-providers'))->toBeNull(); + expect(DomainCache::get('domain-commands'))->toBeNull(); + + $this->artisan('ddd:cache')->execute(); + + expect(DomainCache::get('domain-providers'))->not->toBeNull(); + expect(DomainCache::get('domain-commands'))->not->toBeNull(); + + $this->artisan('cache:clear')->execute(); + + expect(DomainCache::get('domain-providers'))->not->toBeNull(); + expect(DomainCache::get('domain-commands'))->not->toBeNull(); + + $this->artisan('optimize:clear')->execute(); + + expect(DomainCache::get('domain-providers'))->not->toBeNull(); + expect(DomainCache::get('domain-commands'))->not->toBeNull(); +});