diff --git a/src/Traits/Caching.php b/src/Traits/Caching.php index 5d5fccb..7762a59 100644 --- a/src/Traits/Caching.php +++ b/src/Traits/Caching.php @@ -263,6 +263,10 @@ protected function checkCooldownAndRemoveIfExpired(Model $instance) protected function checkCooldownAndFlushAfterPersisting(Model $instance, string $relationship = "") { + if (!$this->isCachable()) { + return; + } + [$cacheCooldown, $invalidatedAt] = $instance->getModelCacheCooldown($instance); if (! $cacheCooldown) { @@ -295,6 +299,10 @@ public function isCachable() : bool $isCacheDisabled = ! Container::getInstance() ->make("config") ->get("laravel-model-caching.enabled"); + if ($isCacheDisabled) { + return false; + } + $allRelationshipsAreCachable = true; if ( @@ -327,7 +335,6 @@ public function isCachable() : bool } return $this->isCachable - && ! $isCacheDisabled && $allRelationshipsAreCachable; }