From a6e208a88ee32a224928d28b5646233384caf7f0 Mon Sep 17 00:00:00 2001 From: Julien Nahum Date: Sat, 2 Dec 2023 19:15:16 +0100 Subject: [PATCH] Remove disable cache in favor flush/forget --- app/Models/Forms/Form.php | 2 +- app/Models/Traits/CachesAttributes.php | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/app/Models/Forms/Form.php b/app/Models/Forms/Form.php index e76f399..6afadac 100644 --- a/app/Models/Forms/Form.php +++ b/app/Models/Forms/Form.php @@ -218,7 +218,7 @@ class Form extends Model implements CachableAttributes public function getMaxNumberOfSubmissionsReachedAttribute() { - $this->disableCache('submissions_count'); + $this->forget('submissions_count'); return ($this->max_submissions_count && $this->max_submissions_count <= $this->submissions_count); } diff --git a/app/Models/Traits/CachesAttributes.php b/app/Models/Traits/CachesAttributes.php index b70d416..0b035d2 100644 --- a/app/Models/Traits/CachesAttributes.php +++ b/app/Models/Traits/CachesAttributes.php @@ -20,8 +20,6 @@ trait CachesAttributes /** @var array */ protected $attributeCache = []; - protected $disabledCache = []; - public static function bootCachesAttributes(): void { static::deleting(function (Model $model): void { @@ -30,18 +28,8 @@ trait CachesAttributes }); } - public function disableCache($key) - { - $this->disabledCache[] = $key; - return $this; - } - public function remember(string $attribute, ?int $ttl, Closure $callback) { - if (in_array($attribute, $this->disabledCache)) { - return value($callback); - } - if ($ttl === 0 || ! $this->exists) { if (! isset($this->attributeCache[$attribute])) { $this->attributeCache[$attribute] = value($callback);