3
3
use GeneaLabs \LaravelModelCaching \CacheKey ;
4
4
use GeneaLabs \LaravelModelCaching \CacheTags ;
5
5
use GeneaLabs \LaravelModelCaching \CachedModel ;
6
+ use Illuminate \Support \Facades \Cache ;
6
7
use Illuminate \Cache \TaggableStore ;
7
8
use Illuminate \Database \Query \Builder ;
8
9
use Illuminate \Database \Eloquent \Builder as EloquentBuilder ;
11
12
trait Cachable
12
13
{
13
14
protected $ isCachable = true ;
15
+ protected static $ isCachableKey = 'genealabs:model-caching:is-disabled ' ;
14
16
15
17
protected function cache (array $ tags = [])
16
18
{
@@ -33,7 +35,8 @@ protected function cache(array $tags = [])
33
35
34
36
public function disableCache ()
35
37
{
36
- session (['genealabs-laravel-model-caching-is-disabled ' => true ]);
38
+ cache ()->forever (self ::$ isCachableKey , true );
39
+
37
40
$ this ->isCachable = false ;
38
41
39
42
return $ this ;
@@ -78,7 +81,7 @@ public static function bootCachable()
78
81
79
82
public static function all ($ columns = ['* ' ])
80
83
{
81
- if (session ( ' genealabs-laravel-model-caching-is-disabled ' )) {
84
+ if (cache ()-> get ( self :: $ isCachableKey )) {
82
85
return parent ::all ($ columns );
83
86
}
84
87
@@ -95,8 +98,8 @@ public static function all($columns = ['*'])
95
98
96
99
public function newEloquentBuilder ($ query )
97
100
{
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 );
100
103
101
104
return new EloquentBuilder ($ query );
102
105
}
0 commit comments