33use GeneaLabs \LaravelModelCaching \CacheKey ;
44use GeneaLabs \LaravelModelCaching \CacheTags ;
55use GeneaLabs \LaravelModelCaching \CachedModel ;
6+ use Illuminate \Support \Facades \Cache ;
67use Illuminate \Cache \TaggableStore ;
78use Illuminate \Database \Query \Builder ;
89use Illuminate \Database \Eloquent \Builder as EloquentBuilder ;
@@ -12,6 +13,8 @@ trait Cachable
1213{
1314 protected $ isCachable = true ;
1415
16+ protected static $ isCachableKey = 'genealabs:model-caching:is-disabled ' ;
17+
1518 protected function cache (array $ tags = [])
1619 {
1720 $ cache = cache ();
@@ -33,7 +36,8 @@ protected function cache(array $tags = [])
3336
3437 public function disableCache ()
3538 {
36- session (['genealabs-laravel-model-caching-is-disabled ' => true ]);
39+ Cache::forever (static ::$ isCachableKey , true );
40+
3741 $ this ->isCachable = false ;
3842
3943 return $ this ;
@@ -78,9 +82,9 @@ public static function bootCachable()
7882
7983 public static function all ($ columns = ['* ' ])
8084 {
81- if (session ( ' genealabs-laravel-model-caching-is-disabled ' )) {
85+ if (Cache:: get ( static :: $ isCachableKey )) {
8286 return parent ::all ($ columns );
83- }
87+ }
8488
8589 $ class = get_called_class ();
8690 $ instance = new $ class ;
@@ -95,8 +99,8 @@ public static function all($columns = ['*'])
9599
96100 public function newEloquentBuilder ($ query )
97101 {
98- if (session ( ' genealabs-laravel-model-caching-is-disabled ' )) {
99- session ()-> forget (' genealabs-laravel-model-caching-is-disabled ' );
102+ if (Cache:: get ( static :: $ isCachableKey )) {
103+ Cache:: forget (static :: $ isCachableKey );
100104
101105 return new EloquentBuilder ($ query );
102106 }
0 commit comments