Skip to content

Commit 3fa1fa1

Browse files
committed
Clean up disabling of cache
1 parent f354365 commit 3fa1fa1

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

src/Traits/Cachable.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
trait Cachable
1212
{
1313
protected $isCachable = true;
14-
protected static $isCachableKey = 'genealabs:laravel-model-caching:is-disabled';
1514

1615
protected function cache(array $tags = [])
1716
{
@@ -43,8 +42,6 @@ protected function addTagsWhenCalledFromCachedBuilder(array $tags) : array
4342

4443
public function disableCache()
4544
{
46-
cache()->forever(self::$isCachableKey, true);
47-
4845
$this->isCachable = false;
4946

5047
return $this;
@@ -89,10 +86,6 @@ public static function bootCachable()
8986

9087
public static function all($columns = ['*'])
9188
{
92-
if (! cache()->get(self::$isCachableKey)) {
93-
return parent::all($columns);
94-
}
95-
9689
$class = get_called_class();
9790
$instance = new $class;
9891
$tags = [str_slug(get_called_class())];
@@ -106,8 +99,8 @@ public static function all($columns = ['*'])
10699

107100
public function newEloquentBuilder($query)
108101
{
109-
if (cache()->get(self::$isCachableKey)) {
110-
cache()->forget(self::$isCachableKey);
102+
if (! $this->isCachable) {
103+
$this->isCachable = true;
111104

112105
return new EloquentBuilder($query);
113106
}

0 commit comments

Comments
 (0)