Skip to content

Commit be74473

Browse files
committed
Merge branch 'hotfix/fix-redundant-class-check'
2 parents 9782a4c + cf08e6d commit be74473

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/Console/Commands/Flush.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ public function handle()
1919
}
2020

2121
$model = new $option;
22+
$usesCachableTrait = collect(class_uses($model))
23+
->contains("GeneaLabs\LaravelModelCaching\Traits\Cachable");
2224

23-
if (! method_exists($model, 'flushCache')) {
25+
if (! $usesCachableTrait) {
2426
$this->error("'{$option}' is not an instance of CachedModel.");
2527
$this->line("Only CachedModel instances can be flushed.");
2628

src/Traits/Cachable.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,25 @@ protected function cache(array $tags = [])
2222
}
2323

2424
if (is_subclass_of($cache->getStore(), TaggableStore::class)) {
25-
if (is_a($this, CachedModel::class)) {
26-
array_push($tags, str_slug(get_called_class()));
27-
}
28-
25+
$tags = $this->addTagsWhenCalledFromCachedBuilder($tags);
2926
$cache = $cache->tags($tags);
3027
}
3128

3229
return $cache;
3330
}
3431

32+
protected function addTagsWhenCalledFromCachedBuilder(array $tags) : array
33+
{
34+
$usesCachableTrait = collect(class_uses($this))
35+
->contains("GeneaLabs\LaravelModelCaching\Traits\Cachable");
36+
37+
if (! $usesCachableTrait) {
38+
array_push($tags, str_slug(get_called_class()));
39+
}
40+
41+
return $tags;
42+
}
43+
3544
public function disableCache()
3645
{
3746
cache()->forever(self::$isCachableKey, true);

0 commit comments

Comments
 (0)