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 ;
1112trait Cachable
1213{
1314 protected $ isCachable = true ;
15+ protected static $ isCachableKey = 'genealabs:model-caching:is-disabled ' ;
1416
1517 protected function cache (array $ tags = [])
1618 {
@@ -33,7 +35,8 @@ protected function cache(array $tags = [])
3335
3436 public function disableCache ()
3537 {
36- session (['genealabs-laravel-model-caching-is-disabled ' => true ]);
38+ cache ()->forever (self ::$ isCachableKey , true );
39+
3740 $ this ->isCachable = false ;
3841
3942 return $ this ;
@@ -78,7 +81,7 @@ public static function bootCachable()
7881
7982 public static function all ($ columns = ['* ' ])
8083 {
81- if (session ( ' genealabs-laravel-model-caching-is-disabled ' )) {
84+ if (cache ()-> get ( self :: $ isCachableKey )) {
8285 return parent ::all ($ columns );
8386 }
8487
@@ -95,8 +98,8 @@ public static function all($columns = ['*'])
9598
9699 public function newEloquentBuilder ($ query )
97100 {
98- if (session ( ' genealabs-laravel-model-caching-is-disabled ' )) {
99- session ()->forget (' genealabs-laravel-model-caching-is-disabled ' );
101+ if (cache ()-> get ( self :: $ isCachableKey )) {
102+ cache ()->forget (self :: $ isCachableKey );
100103
101104 return new EloquentBuilder ($ query );
102105 }
0 commit comments