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 ;
@@ -12,6 +13,8 @@ trait Cachable
12
13
{
13
14
protected $ isCachable = true ;
14
15
16
+ protected static $ isCachableKey = 'genealabs:model-caching:is-disabled ' ;
17
+
15
18
protected function cache (array $ tags = [])
16
19
{
17
20
$ cache = cache ();
@@ -33,7 +36,8 @@ protected function cache(array $tags = [])
33
36
34
37
public function disableCache ()
35
38
{
36
- session (['genealabs-laravel-model-caching-is-disabled ' => true ]);
39
+ Cache::forever (static ::$ isCachableKey , true );
40
+
37
41
$ this ->isCachable = false ;
38
42
39
43
return $ this ;
@@ -78,9 +82,9 @@ public static function bootCachable()
78
82
79
83
public static function all ($ columns = ['* ' ])
80
84
{
81
- if (session ( ' genealabs-laravel-model-caching-is-disabled ' )) {
85
+ if (Cache:: get ( static :: $ isCachableKey )) {
82
86
return parent ::all ($ columns );
83
- }
87
+ }
84
88
85
89
$ class = get_called_class ();
86
90
$ instance = new $ class ;
@@ -95,8 +99,8 @@ public static function all($columns = ['*'])
95
99
96
100
public function newEloquentBuilder ($ query )
97
101
{
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 );
100
104
101
105
return new EloquentBuilder ($ query );
102
106
}
0 commit comments